onload event of an asp.net content page

I've successfully included some javascript in a content page for the interaction of radio buttons and a dropdownbox when each is selected/clicked.  Now I want to perform some functions when the content page loads but I'm having trouble.  

I tried this in my asp Page_Load event but it's not firing:
       If Not Page.ClientScript.IsClientScriptBlockRegistered(t, "onLoad") Then
            Me.ClientScript.RegisterClientScriptInclude("onLoad", "~/scripts/JScript.js")
        End If

Here are the contents of the above script file:
  function onLoad() {
       alert('hitting load of counts');
       document.getElementById('selMonth').options[+document.getElementById('txtHiddenMonth').value].selected = true ;

   }

???
LVL 1
bozworthyAsked:
Who is Participating?
 
nouloukConnect With a Mentor Commented:
It works fine for me.
I put the script inside Head tags. What about you ?
0
 
nouloukCommented:
Hi bozworthy,

Where is  the window.onload = onLoad() event ?
0
 
bozworthyAuthor Commented:
When I select 'window' on the left dropdown and 'onload' event from the right, it places the following two segments of code in my file:

<script language="javascript" type="text/javascript" for="window" event="onload">
// <!CDATA[
return window_onload()
// ]]>
</script>

function window_onload() {

}

I'm getting the design time error "Element 'for' is not a valid attribute of element 'script'.  Same thing for 'event'.    The script blows up at run time.  What's wrong?


0
 
bozworthyAuthor Commented:
I threw <h1>  </h1> around the script and it worked.  Thanks!!
0
All Courses

From novice to tech pro — start learning today.