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

Page_Unload problem in .NET 1.1?

P: n/a
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
Share this Question
Share on Google+
2 Replies


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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.