473,398 Members | 2,335 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,398 software developers and data experts.

onbeforeunload error

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
Sep 5 '06 #1
1 4099
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


Sep 5 '06 #2

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

Similar topics

4
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
12
by: Scott Mitchell | last post by:
I am using the onbeforeunload client-side event to prompt a user when leaving a page after they have made changes, as discussed in this article: Using ASP.NET to Prompt a User to Save When Leaving...
5
by: crjunk | last post by:
I'm working with a script that uses the OnBeforeUnload event. If the user has made changes to a record and has not saved the record, the script will inform the user and give them a chance to go...
6
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or...
4
by: sowencheung | last post by:
the bug of onbeforeunload is so obvious! in IE 6 it will popup twice "sometimes" I am using the following code window.onbeforeunload = null; window.onbeforeunload = confirmExit; var...
8
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...
0
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...

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.