Page_Unload event firing twice.

L

Larry Morris

The following code, pasted into a web form with a link button on it, will
cause the page_unload event to fire twice. If I remove the
response.redirect, the problem goes away :). I've got a work around, but I'm
curious how one is supposed to programmatically navigate between web pages
without the page_unload event firing twice.

Thanks,

Larry







Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Stop

End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Unload

Stop

End Sub

Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LinkButton1.Click

Response.Redirect("http://www.microsoft.com")

End Sub

End Class
 
T

tzeng9

As the page is loaded the first time, it will invoke Page_Unload the
first time finally but just before rendering the HTML content to the
browser,

Then the link butten will invoke page postback, in which the
page_unload will be invoked again.

If just want to invoke once, try to use if(IsPostBack) to filter it.
HTH.

T.Z
 
T

tzeng9

As the page is loaded the first time, it will invoke Page_Unload the
first time finally but just before rendering the HTML content to the
browser,

Then the link butten will invoke page postback, in which the
page_unload will be invoked again.

If just want to invoke once, try to use if(IsPostBack) to filter it.
HTH.

T.Z
 
L

Larry Morris

I know that; What happens in this case is:

Page_Load,
Page_Unload,

Page_Load,
LinkButton1_Click,
Page_Unload,
Page_Unload.

Notice the Page_Unload event fired twice. What is it about the
Response.Redirect causes two page_unload events?
 
B

bruce barker

every page request has a load and unload. a redirect in the response tells
the browser to request a new page. page unload has nothing to do with the
browser, its just the last step in the creating the html for the page, it
used to release objects you created during building the page.

-- bruce (sqlwork.com)



| I know that; What happens in this case is:
|
| Page_Load,
| Page_Unload,
|
| Page_Load,
| LinkButton1_Click,
| Page_Unload,
| Page_Unload.
|
| Notice the Page_Unload event fired twice. What is it about the
| Response.Redirect causes two page_unload events?
|
| | > As the page is loaded the first time, it will invoke Page_Unload the
| > first time finally but just before rendering the HTML content to the
| > browser,
| >
| > Then the link butten will invoke page postback, in which the
| > page_unload will be invoked again.
| >
| > If just want to invoke once, try to use if(IsPostBack) to filter it.
| > HTH.
| >
| > T.Z
| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top