In the past developers used <body onload="..."> to execute some script as soon as the page is loaded. Nowadays this is rather old-fashioned, no matter how you look at it. What's more, it doesn't work as expected in ASP.NET AJAX websites. Consider the following example:
In this case MyFunction() will be executed after all client-side control instances have been created and the script will work as expected. Another benefit of using the second approach is that multiple event handlers can be added to the client page load event, whereas only one handler is added if <body onload="..."> is used.
Iana Tsolova is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.
Subscribe to be the first to get our expert-written articles and tutorials for developers!