473,756 Members | 3,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="Syste m.Web.UI.Page"
smartNavigation ="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<meta name="GENERATOR " Content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript"
content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<script language="javas cript">
function __OnLoad()
{
alert("Form1
Load");
}
function __OnUnLoad()
{
alert("Form1
UnLoad");
}
</script>
<script language="C#"
runat="server">
void btnTransferForm 2_Click
(object sender, System.EventArg s e)
{

this.Server.Tra nsfer("Webform2 .aspx");
}
void btnRedirForm2_C lick
(object sender, System.EventArg s e)
{

this.Response.R edirect("Webfor m2.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="btnTransfer Form2" runat="server"
OnClick="btnTra nsferForm2_Clic k" Text="Transfer To
Form2"></asp:Button>&nbs p;click
this button to transfer to
page 2 and see that the unload jscript routine does
not fire</P>
<P>
<asp:Button
id="btnRedirFor m2" runat="server"
OnClick="btnRed irForm2_Click" Text="Redirect To
Form2"></asp:Button>&nbs p;this
will fire the unload event
</P>
<script language="javas cript">
<!--
window.attachEv ent
("onload", __OnLoad);

//document.body.o nload = __OnLoad;
window.attachEv ent
("onunload", __OnUnLoad);

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

*************** ****
Webform2.aspx
*************** ****
<%@ Page language="c#" Inherits="Syste m.Web.UI.Page" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2 </title>
<meta name="GENERATOR " Content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript"
content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<script language="javas cript">
function __OnLoad()
{
alert("Form2
Load");
}
function __OnUnLoad()
{
alert("Form2
UnLoad");
}
</script>
<script language="C#"
runat="server">
void btnTransferForm 1_Click
(object sender, System.EventArg s e)
{

this.Server.Tra nsfer("WebForm1 .aspx");
}

void btnRedirForm1_C lick
(object sender, System.EventArg s e)
{

this.Response.R edirect("Webfor m1.aspx");
}
</script>
<P>Form2.aspx SmartNav=False</P>
<P><a
href="WebForm1. aspx">Naviagate to Webform1.aspx</a></P>
<P>
<asp:Button
id="btnTransfer Form1" runat="server"
OnClick="btnTra nsferForm1_Clic k" Text="Transfer To
Form1"></asp:Button></P>
<P>
<asp:Button
id="btnRedirFor m1" runat="server"
OnClick="btnRed irForm1_Click" Text="Redirect To
Form1"></asp:Button></P>
<script language="javas cript">
<!--
window.attachEv ent
("onload", __OnLoad);

//document.body.o nload = __OnLoad;
window.attachEv ent
("onunload", __OnUnLoad);

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

..
Nov 18 '05 #1
1 2933
Undercover747
1 New Member
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="Syste m.Web.UI.Page"
smartNavigation ="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<meta name="GENERATOR " Content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript"
content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<script language="javas cript">
function __OnLoad()
{
alert("Form1
Load");
}
function __OnUnLoad()
{
alert("Form1
UnLoad");
}
</script>
<script language="C#"
runat="server">
void btnTransferForm 2_Click
(object sender, System.EventArg s e)
{

this.Server.Tra nsfer("Webform2 .aspx");
}
void btnRedirForm2_C lick
(object sender, System.EventArg s e)
{

this.Response.R edirect("Webfor m2.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="btnTransfer Form2" runat="server"
OnClick="btnTra nsferForm2_Clic k" Text="Transfer To
Form2"></asp:Button>&nbs p;click
this button to transfer to
page 2 and see that the unload jscript routine does
not fire</P>
<P>
<asp:Button
id="btnRedirFor m2" runat="server"
OnClick="btnRed irForm2_Click" Text="Redirect To
Form2"></asp:Button>&nbs p;this
will fire the unload event
</P>
<script language="javas cript">
<!--
window.attachEv ent
("onload", __OnLoad);

//document.body.o nload = __OnLoad;
window.attachEv ent
("onunload", __OnUnLoad);

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

*************** ****
Webform2.aspx
*************** ****
<%@ Page language="c#" Inherits="Syste m.Web.UI.Page" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2 </title>
<meta name="GENERATOR " Content="Micros oft
Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript"
content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post"
runat="server">
<script language="javas cript">
function __OnLoad()
{
alert("Form2
Load");
}
function __OnUnLoad()
{
alert("Form2
UnLoad");
}
</script>
<script language="C#"
runat="server">
void btnTransferForm 1_Click
(object sender, System.EventArg s e)
{

this.Server.Tra nsfer("WebForm1 .aspx");
}

void btnRedirForm1_C lick
(object sender, System.EventArg s e)
{

this.Response.R edirect("Webfor m1.aspx");
}
</script>
<P>Form2.aspx SmartNav=False</P>
<P><a
href="WebForm1. aspx">Naviagate to Webform1.aspx</a></P>
<P>
<asp:Button
id="btnTransfer Form1" runat="server"
OnClick="btnTra nsferForm1_Clic k" Text="Transfer To
Form1"></asp:Button></P>
<P>
<asp:Button
id="btnRedirFor m1" runat="server"
OnClick="btnRed irForm1_Click" Text="Redirect To
Form1"></asp:Button></P>
<script language="javas cript">
<!--
window.attachEv ent
("onload", __OnLoad);

//document.body.o nload = __OnLoad;
window.attachEv ent
("onunload", __OnUnLoad);

//document.body.o nunload = __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
2680
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 the JavaScript function. The function copies the data into a server textbox control. Step 2: The user presses the VS generated "Step 2" button, which calls the
1
2654
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 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.
4
4481
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 server event to fire to update the database. I've successfully done this with a normal webcontrol via: myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');" In that case, myControl is an asp:button on the page. In the...
1
5240
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 appear to be the result of double-clicking the submit button on the form. The form has three ASP:Button tags, each of which gets translated into INPUT TYPE="SUBMIT" HTML elements. One submits the form's data. One logs the user out. And the other...
1
2517
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 the java script validation as well as the click in code behind? How can this be done ? Can I call the code behind from the javascript function? If not can i have a separate procedure in C# file and call it from the javascript function? If so...
2
4924
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 being updated by some other process through remoting. When the page loads, I init the tree, and in my browser I can see the initialized tree. The problem is that every time that I receive update to tree from the remote process,
7
1985
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 declaration/directive tag - when I go to test the page it goes into an infinite loop (in debugger I've tried to break at the Page_Load method but the loop occurs before the method can even be reached)! I've rebooted the server...
0
1518
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 functionality, with callbacks. I can clearly see that the page does not refresh, which is good, as this was my intention to begin with. I also closely inspected the client-side sources (using "Instant
8
2186
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 that? Thank you Max
0
9455
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9869
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9838
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.