Why can't we use Response.Write on the Unload Event page?

I use the Respose.Writeon event Page_Unload, then I get an error

In this context, the answer is not available.

May I find out why we cannot use?

protected void Page_Unload(object sender, System.EventArgs e)
{
  Response.Write(" hi ");
}
+3
source share
5 answers

This is because the event is Unloadfired after the page has been displayed. The page has already been completed and there is no longer a response stream that you can record on the way to the browser.

+4
source

From an MSDN article in ASP.NET Lifecyle :

, . , Response.Write, .

, , .

. , . , .

MSDN:

:

... , , .

:

... , , , .

+4

Unload , ​​ . .

ASP.NET.

+3

. , . , Response.Write, exception.

HTML HTML . , .

ASP.NET

+2

Read the page life cycle: http://msdn.microsoft.com/en-us/library/ms178472.aspx

UnLoad appears after rendering, so at that moment you displayed everything that you can on the screen.

+2
source

All Articles