Wednesday, November 7, 2007

JavaScript Onload event on Visual Studio 2005 Content pages.

Issue

If you create Master/Content page setup in Visual Studio 2005, you quickly realize that Content pages do not include essential HTML tags such as Head and body. Therefore, Onload event of JavaScript cannot be used on the body tag.

Workaround

Use the following in you Content page:

<script type="text/javascript" >
  window.onload=MyFunction;
< /script>

MyFunction is a placeholder for your function name.

Note: there are no parentheses preceding the function name. If parentheses are used in front of the function name, user will recieve JavaScript runtime error "Not implemented".

No comments: