473,545 Members | 769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page_Unload event firing twice.

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.redire ct, the problem goes away :). I've got a work around, but I'm
curious how one is supposed to programmaticall y 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.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

Stop

End Sub

Private Sub Page_Unload(ByV al sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Unload

Stop

End Sub

Private Sub LinkButton1_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles LinkButton1.Cli ck

Response.Redire ct("http://www.microsoft.c om")

End Sub

End Class
Nov 19 '05 #1
4 6074
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
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
I know that; What happens in this case is:

Page_Load,
Page_Unload,

Page_Load,
LinkButton1_Cli ck,
Page_Unload,
Page_Unload.

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

"tzeng9" <tz****@gmail.c om> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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
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******@relia soft.biz> wrote in message
news:et******** ******@TK2MSFTN GP09.phx.gbl...
| I know that; What happens in this case is:
|
| Page_Load,
| Page_Unload,
|
| Page_Load,
| LinkButton1_Cli ck,
| Page_Unload,
| Page_Unload.
|
| Notice the Page_Unload event fired twice. What is it about the
| Response.Redire ct causes two page_unload events?
|
| "tzeng9" <tz****@gmail.c om> wrote in message
| news:11******** **************@ z14g2000cwz.goo glegroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
15677
by: Robert Scheer | last post by:
Hi. Debugging one of my pages I noticed that everytime I call the page, the first event to run is Page_Load and after it the Page_Unload. If I postback to the page the Page_Unload runs again. Shouldn't the Page_Unload event runs only when I close the page or submit the page? I can't understand why the Unload event runs when I load the page...
19
3455
by: Heidi Hundåla | last post by:
Hi ! I have a Wep App in C#. Page_Unload fires after Page_Load, and it seems totally unreasonable when you want to use this event when you _leave_ the page. In my project we wanted to use the Page_Unload - event to clean up the Session variables, but when it turns out that it fires before the end, it screws up the code, and
0
1407
by: chefo | last post by:
Well, the subject describes my problem quite well :-) Here is some additional information. I use a common base class for all the pages in my project. It is derived from Page and it is not abstract, because there was some problem with the compilation. I define a common Page_Unload handler in the base class and subscribe for the event like...
4
3955
by: Seraph | last post by:
Again, I'm rather new here, so if I fail to follow any etiquette, please forgive me and let me know what I've done wrong, but I think this might interest quite a few people. One of my colleaques was endeavoring to create a custom user control to make things a bit simpler, but she noticed that her Page_Load eventhandler was firing twice. So...
0
1692
by: JeffM | last post by:
This seems odd, but it appears that the Page_Unload event is fired twice on a Response.Redirect or a Server.Transfer. The output below demonstrates that during the move from the first to the 2nd page, the event fires twice on the 1st page during Postback. The "var" set the first time is visible the 2nd time it fires. Anyone else notice...
7
2107
by: Cenk | last post by:
Hi, After converting my projects to ASP.Net 2.0 I have seen a problem with Page_unload. Ä°n framework 1.1 page_unload event fires when you are leaving the page or has closed the browser window. Now in 2.0 when you initally load the page Page_unload event fires after page_load event. In some of our aspx pages we craete some versions of...
0
1157
by: Stina | last post by:
I have a problem with the Page_Unload event being called twice in a row on a redirect and I just can't figure out why. I have seen other threads on this subject but not found a solution to the problem. This is what happens: When page is loaded Page_Load Page_Unload
2
1930
by: Dan Lichiardopol | last post by:
Hi there! I'm trying to use page unload event in order to write info to a text file. Everything works fine, unless code contains a call to Response.End. Then, the unload event appears to be triggered twice. I have created a very simple test page that illustrates this behaviour. The problem does not occur under .NET 2.0. If you would...
5
15264
by: =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post by:
Hi there, I'm using Web Developer Express 2005 in my ASP.NET learning. I tried creating a simple aspx page using "code-behind" approach. I noticed that protected void Page_Load event method appears automatically in mypage.aspx.cs Ok, so far so good, but now I need to code something when Page_Unload occurs but I can't find a place to choose...
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.