Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

response in page_unload event

Status
Not open for further replies.

tfstom

Programmer
Sep 28, 2002
190
US
I have page that just shows the order of page events firing.

It works fine unless I have a response.write in the page_unload section.

I was wondering why that is the case?

The page is:

Code:
  <%@ Page Language="VB" Debug="true" %>
  
  <Script Runat="Server">

Sub Page_Init
  response.write("Init Event<br>")
End Sub

Sub Page_PreRender
  response.write("PreRender Event<br>")
End Sub

Sub Page_Unload
  response.write("Unload Event<br>")
End Sub

Sub Page_Load
  Dim RanNum As New Random
  
  response.write("Load Event<br>")
  
  response.write("isPostBack = " & isPostBack & "<BR>" & "Page.isPostBack = " & Page.isPostBack & "<br>")
  
  response.write("Random number = " & RanNum.Next( 1, 11 ) & "<br>")
  
End Sub

</Script>

<html>
<head><title>IsPostBack.aspx</title></head>
<body>

<form Runat="Server">

<asp:button Text="Click Here!" Runat="Server"/>
<p>

</form>

</body>
</html>

The error I get is:

Code:
Response is not available in this context. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Response is not available in this context.

Source Error: 


Line 12: 
Line 13: Sub Page_Unload
Line 14:   response.write("Unload Event<br>")
Line 15: End Sub
Line 16: 
 

Source File: c:\inetpub\[URL unfurl="true"]wwwroot\ispostbackEvents.aspx[/URL]    Line: 14 

Stack Trace: 


[HttpException (0x80004005): Response is not available in this context.]
   System.Web.UI.Page.get_Response() +63
   ASP.IsPostBackEvents_aspx.Page_Unload() in c:\inetpub\[URL unfurl="true"]wwwroot\ispostbackEvents.aspx:14[/URL]
   System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
   System.Web.UI.Control.OnUnload(EventArgs e) +67
   System.Web.UI.Control.UnloadRecursive(Boolean dispose) +121
   System.Web.UI.Page.ProcessRequestCleanup() +24
   System.Web.UI.Page.ProcessRequest() +218
   System.Web.UI.Page.ProcessRequest(HttpContext context) +18
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

Thanks,

Tom
 
tf: I tried your code and it worked errorless for me although I did not get the print out of the Unload string.

Also, thanks for the random number generator, I was just in the market for one of those this weekend. Someone will come by with an explanation I'm sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top