473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Page_Unload problem in .NET 1.1?

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 examine the
logfile.txt created by the page running under 1.1, you will notice two
entries for unload event.

I'm not sure that is this really a bug or something that was supposed
to be this way. Is this, by any chance, a documented issue? I could not
find anything related to it. The easy way out, would be to upgrade to
..NET 2.0 - but that is not an option at the time being. Any suggestions
on a workaround, would be appreciated.

Thanks,
Dan

Test page code follows:

--- code begin ---
<%@ Page Language="vb"%>
<%@ Import Namespace="System.IO" %>
<%
Response.Write("Running .NET ver. " &
System.Environment.Version.ToString() & "<br />")
Response.Write("Before calling Response.End()<br />")
Response.End() ' triggers OnUnload twice on .NET 1.1
Response.Write("After calling Response.End()<br />") ' should never
show
%>
<script language="vb" runat="server">
protected sub Page_Unload(sender as object, e as EventArgs)
dim s as StreamWriter
s = File.AppendText(Server.MapPath("logfile.txt"))
s.Writeline("OnUnload")
s.Close()
end sub
</script>
--- code end ---

Testing environment:
-----------------------------
I have .net 1.1 and 2.0 installed on an IIS 5.1 running under XP
Professional. Two application domains were created one for 1.1 and
another one for 2.0. No modifications were done to web.config file.
(aspnet user must have rights to create & modify files under the app
domain).

Dec 21 '06 #1
2 1908
I have no idea if this is a bug or not. If it is indeed a bug, I would
suggest having a page level variable that is a boolean that keeps track of
whether or not Page_Unload has run. Set it in your handler, and in the
beginning always check to make sure it hasn't been run already. If it has,
just do nothing. This would at least avoid having your code run twice.

"Dan Lichiardopol" <dl******@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
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 examine the
logfile.txt created by the page running under 1.1, you will notice two
entries for unload event.

I'm not sure that is this really a bug or something that was supposed
to be this way. Is this, by any chance, a documented issue? I could not
find anything related to it. The easy way out, would be to upgrade to
.NET 2.0 - but that is not an option at the time being. Any suggestions
on a workaround, would be appreciated.

Thanks,
Dan

Test page code follows:

--- code begin ---
<%@ Page Language="vb"%>
<%@ Import Namespace="System.IO" %>
<%
Response.Write("Running .NET ver. " &
System.Environment.Version.ToString() & "<br />")
Response.Write("Before calling Response.End()<br />")
Response.End() ' triggers OnUnload twice on .NET 1.1
Response.Write("After calling Response.End()<br />") ' should never
show
%>
<script language="vb" runat="server">
protected sub Page_Unload(sender as object, e as EventArgs)
dim s as StreamWriter
s = File.AppendText(Server.MapPath("logfile.txt"))
s.Writeline("OnUnload")
s.Close()
end sub
</script>
--- code end ---

Testing environment:
-----------------------------
I have .net 1.1 and 2.0 installed on an IIS 5.1 running under XP
Professional. Two application domains were created one for 1.1 and
another one for 2.0. No modifications were done to web.config file.
(aspnet user must have rights to create & modify files under the app
domain).

Dec 21 '06 #2
Thanks Marina,

That's definitely an option.

Marina Levit [MVP] wrote:
I have no idea if this is a bug or not. If it is indeed a bug, I would
suggest having a page level variable that is a boolean that keeps track of
whether or not Page_Unload has run. Set it in your handler, and in the
beginning always check to make sure it hasn't been run already. If it has,
just do nothing. This would at least avoid having your code run twice.

"Dan Lichiardopol" <dl******@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
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 examine the
logfile.txt created by the page running under 1.1, you will notice two
entries for unload event.

I'm not sure that is this really a bug or something that was supposed
to be this way. Is this, by any chance, a documented issue? I could not
find anything related to it. The easy way out, would be to upgrade to
.NET 2.0 - but that is not an option at the time being. Any suggestions
on a workaround, would be appreciated.

Thanks,
Dan

Test page code follows:

--- code begin ---
<%@ Page Language="vb"%>
<%@ Import Namespace="System.IO" %>
<%
Response.Write("Running .NET ver. " &
System.Environment.Version.ToString() & "<br />")
Response.Write("Before calling Response.End()<br />")
Response.End() ' triggers OnUnload twice on .NET 1.1
Response.Write("After calling Response.End()<br />") ' should never
show
%>
<script language="vb" runat="server">
protected sub Page_Unload(sender as object, e as EventArgs)
dim s as StreamWriter
s = File.AppendText(Server.MapPath("logfile.txt"))
s.Writeline("OnUnload")
s.Close()
end sub
</script>
--- code end ---

Testing environment:
-----------------------------
I have .net 1.1 and 2.0 installed on an IIS 5.1 running under XP
Professional. Two application domains were created one for 1.1 and
another one for 2.0. No modifications were done to web.config file.
(aspnet user must have rights to create & modify files under the app
domain).
Dec 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: tascien | last post by:
I found a use for Page_Unload event method... here is the scenario: 1. Page.aspx has DoStuff.ascx in it. 2. DoStuff.ascx has a button that updates child control label lbXml depending on user...
1
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....
19
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...
4
by: Larry Morris | last post by:
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...
3
by: Andrew Vickers | last post by:
Hi, I'm just trying to manually add a page_unload function in my code-behind module, but with no success. Can anyone help me with the correct syntax to add the function to my code? I've tried...
0
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...
0
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...
7
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....
2
by: RAM | last post by:
Hello, I am learning .NET 2.0 and I have written simple application with Default.aspx page and logging in Logon.aspx/Logon.aspx.cs. After Page_Unload of Logon.aspx.cs (I have checked by debugging)...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.