By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

Page_Unload event firing twice.

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Nov 19 '05 #2

P: n/a
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

Nov 19 '05 #3

P: n/a
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?

"tzeng9" <tz****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 19 '05 #4

P: n/a
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)

"Larry Morris" <lw******@reliasoft.biz> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
| 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?
|
| "tzeng9" <tz****@gmail.com> wrote in message
| news:11**********************@z14g2000cwz.googlegr oups.com...
| > 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
| >
|
|
Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.