472,093 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

smart nav = no unload event

hal
I have an application that includes an activex component
that consumes resources that must be released when the a
page is unloaded.

Toward this end I subscribe to the unload event of the
body of my page in javascript.

However, if I turn on smart navigation, any button that
does a server.transfer fails to fire the javascript unload
event.

I have included two example pages that duplicate the
behavior. To run the example, create two pages called
webform1.aspx and webform2.aspx and copy the html and code
from this message.

Any explanation or work around is greatly appreciated!

Thanks for your time

Hal

**********************
Webform1.aspx:
**********************
<%@ Page language="c#" Inherits="System.Web.UI.Page"
smartNavigation="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<meta name="GENERATOR" Content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<script language="javascript">
function __OnLoad()
{
alert("Form1
Load");
}
function __OnUnLoad()
{
alert("Form1
UnLoad");
}
</script>
<script language="C#"
runat="server">
void btnTransferForm2_Click
(object sender, System.EventArgs e)
{

this.Server.Transfer("Webform2.aspx");
}
void btnRedirForm2_Click
(object sender, System.EventArgs e)
{

this.Response.Redirect("Webform2.aspx");
}
</script>
<P>Form1.aspx SmartNav=True
</P>
<P><a
href="WebForm2.aspx">Naviagate to
Webform2.aspx</a>&nbsp;this will also fire
the unload event</P>
<P>
<asp:Button
id="btnTransferForm2" runat="server"
OnClick="btnTransferForm2_Click" Text="Transfer To
Form2"></asp:Button>&nbsp;click
this button to transfer to
page 2 and see that the unload jscript routine does
not fire</P>
<P>
<asp:Button
id="btnRedirForm2" runat="server"
OnClick="btnRedirForm2_Click" Text="Redirect To
Form2"></asp:Button>&nbsp;this
will fire the unload event
</P>
<script language="javascript">
<!--
window.attachEvent
("onload", __OnLoad);

//document.body.onload = __OnLoad;
window.attachEvent
("onunload", __OnUnLoad);

//document.body.onunload = __OnUnLoad;
-->
</script>
</form>
</body>
</HTML>

*******************
Webform2.aspx
*******************
<%@ Page language="c#" Inherits="System.Web.UI.Page" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft
Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<script language="javascript">
function __OnLoad()
{
alert("Form2
Load");
}
function __OnUnLoad()
{
alert("Form2
UnLoad");
}
</script>
<script language="C#"
runat="server">
void btnTransferForm1_Click
(object sender, System.EventArgs e)
{

this.Server.Transfer("WebForm1.aspx");
}

void btnRedirForm1_Click
(object sender, System.EventArgs e)
{

this.Response.Redirect("Webform1.aspx");
}
</script>
<P>Form2.aspx SmartNav=False</P>
<P><a
href="WebForm1.aspx">Naviagate to Webform1.aspx</a></P>
<P>
<asp:Button
id="btnTransferForm1" runat="server"
OnClick="btnTransferForm1_Click" Text="Transfer To
Form1"></asp:Button></P>
<P>
<asp:Button
id="btnRedirForm1" runat="server"
OnClick="btnRedirForm1_Click" Text="Redirect To
Form1"></asp:Button></P>
<script language="javascript">
<!--
window.attachEvent
("onload", __OnLoad);

//document.body.onload = __OnLoad;
window.attachEvent
("onunload", __OnUnLoad);

//document.body.onunload = __OnUnLoad;
-->
</script>
</form>
</body>
</HTML>

Nov 18 '05 #1
1 2565
Hi,

You might use RegisterStartupscript to render client side script. That
script uses attachEvent to attaché event to event handler
Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Harry J. Smith | last post: by
1 post views Thread by David A. Beck | last post: by
1 post views Thread by Hal | last post: by
6 posts views Thread by Mike | last post: by
1 post views Thread by Mike Labosh | last post: by
3 posts views Thread by Gauthier Segay | last post: by
5 posts views Thread by =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post: by
reply views Thread by leo001 | last post: by

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.