473,414 Members | 1,599 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,414 software developers and data experts.

smart nav = no client side unload event

Hal
My most sincere gratitude to anyone who can help me work
around this!

I have work that needs to be done in javascript on the
client whenever a page is unloaded.

To this end, I subscribe to the unload event (client side
not server side) of the <body> HTML element through
javascript.

However, if I turn on smart navigation, any button that
does a server.transfer fails to fire the client side
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 2913
My advice would be to turn smart nav off. It wreaks havoc with javascript. There are other ways to accomplish what smart nav does without the side effects. If your users are using a browser other than IE it doesn't work anyway.

My most sincere gratitude to anyone who can help me work
around this!

I have work that needs to be done in javascript on the
client whenever a page is unloaded.

To this end, I subscribe to the unload event (client side
not server side) of the <body> HTML element through
javascript.

However, if I turn on smart navigation, any button that
does a server.transfer fails to fire the client side
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>

..
May 4 '06 #2

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

Similar topics

1
by: Jim Hammond | last post by:
I can get data from a client-side assembly to the server in two manual steps, but I need to be able to do it in one step. Step 1: The user presses the manually coded "Step 1" button, which calls...
1
by: hal | last post by:
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...
4
by: Barb | last post by:
I have a user control as my Save button for my page. When the Save button is clicked, I want some client-side validation to take place from a javascript function in the page, and then I'd like the...
1
by: rmgalante | last post by:
I have written an ASP.Net application that uses the standard client-side and server-side validation for various fields on the form. Some of the customers that use the form report symptoms that...
1
by: vidya | last post by:
Hi, I have a button which is a web control. I have some validation in javascript for the button in .aspx file and some in the button onclick event in code behind(C#). I need to get through both...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
7
by: Kewlpack | last post by:
Okay - this is stumping me. I've used .Net since 1.0 release and never had this trouble before... In one of my new projects, if I enable the SmartNavigation="True" in the Page...
0
by: alrotem | last post by:
Hi, I'm using an <asp:TreeViewcontrol on my page. Combining the TreeView's OnTreeNodePopulate server-side event handler, and the PopulateOnDemand set to "true" on each node, I get client-based...
8
by: MAX2006 | last post by:
Hi, I am doing some client side javascipt work. I have a handler for window.onUnload event and within the code; I need to know the name of the asp.net button caused the postback. How can I do...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.