add <body onunload="blah();">

  • Thread starter Thread starter Oleg Ogurok
  • Start date Start date
O

Oleg Ogurok

Hi all,

Is there a way to add a client side onunload statement into the <body> tag
of a page?
Thanks.

-Oleg.
 
I wouldn't waste your time, it's not reliable.
Also, it's not an ASP(X) issue at all since it would never make the second
trip.
 
Oleg said:
Is there a way to add a client side onunload statement into the
<body> tag of a page?

Sure, just add an ID and Runat attribute to the BODY tag.
e.g.
<BODY id="Body1" runat="server">

Then in the code-behind file, add a class var such as
protected System.Web.UI.HtmlControls.HtmlGenericControl Body1;

Then in the Form_Load event, add the client-side client event handler
Body1.Attributes.Add("onUnload", "Body1_OnUnload");

Or course you will need the client-side script to handle the onUnload
event. ;-)
 
Back
Top