Hi,
yes it is not valid.
You can change the body tag to be server-side object
<body id="BodyTag" runat="server">
and then add the call via Attributes collection in code:
BodyTag.Attributes["onbeforeunload"] = "closeIt()";
And with ASP.NET 2.0, you can also use expando attribute mechanism to
preserve compatibility with rendered markup. Then just have <bodyalso with
ID and runat="server" and the relevant code
Page.ClientScript.RegisterExpandoAttribute(BodyTag .ClientID,
"onbeforeunload", "closeIt");
string script=String.Format("eval(\"{0}.onbeforeunload = \" +
{0}.onbeforeunload + \";\");",BodyTag.ClientID);
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), "evaling",
script, true);
(closeIt is function which is called when onbeforeunload fires)
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"David" <dl*****@lifetimeinc.comwrote in message
news:u$**************@TK2MSFTNGP05.phx.gbl...
>I am using a process to warn users when they leave a page that there have
been changes made. I took the example directly from Microsoft example I
found in searching for help on the event onbeforeunload. I have the event
inside the BODY element in my aspx page and it seems to work just fine.
However, I still get a flash of a page error in the lower left corner of my
browser and the Visual Studio 2005 "souce" page shows the event name
underlined with mouseover message "Validation (XHTML 1.0 Transitional):
Attribute 'onbeforeunload' is not a valid attribute of element 'body'."
Is there anything I can do to get rid of this error? Thanks.
David