Solved

Using   window.onLoad = or   window.onLoad +=

Posted on 2013-12-18
2
273 Views
Last Modified: 2013-12-18
I'm trying to avoid ViewState Mac errors and one of the solutions is to disable the form and re-enable it when the page loads to prevent premature submissions of the form before it has finished loading (see here for a good discussion of the options - http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx)

To enable the form again the above page has this:

  function enableForm() { 
      document.getElementById("form").disabled = false; 
  } 

  window.onLoad = enableForm();

Open in new window


I wasn't sure if this would replace any existing window.onLoad event handlers, and if you are supposed to enter

  window.onLoad += enableForm();

and if you are supposed to do this whether it would put "enableForm()" as the first function called after onLoad?
0
Comment
Question by:purplesoup
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39726398
See by yourself :

http://jsfiddle.net/yuDbL/
http://jsfiddle.net/yuDbL/1/

Your should have IE9+ to see the alerts on the second one else you need to use attachEvent instead addEventListener : http://msdn.microsoft.com/en-us/library/ie/ms536343(v=vs.85).aspx

So as you can see he order is very important. If you want your code run first, you must put it in the first place but if you use window.onload it MAY BE overwritten by the others scripts that come after your script

I would suggest you to use addEventListener and put your script in the first position in the HEAD section
0
 

Author Closing Comment

by:purplesoup
ID: 39726759
Excellent - thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question