This is what I do in my pages
//Include an external Javascript
if (!Page.ClientScript.IsClientScriptIncludeRegistered("displayRow"))
Page.ClientScript.RegisterClientScriptInclude("displayRow", ResolveClientUrl("showhide.js"));
//call the function
string temp = "selectiveDisplayS3(" + stype + ")";
//find the body tag
HtmlGenericControl body = (HtmlGenericControl)Page.FindControl("Body");
//if your body is in master page
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("Body");
body.Attributes.Add("onload", temp);
To get this to work, you need set this
<body runat="server">