Hi, i've added to the master page my script "myscript.js". Then, in a content page, i would like to load myscript() at startup (body onload).
How can i do this ?
Thank you in advance !
Regards
Hi, i've added to the master page my script "myscript.js". Then, in a content page, i would like to load myscript() at startup (body onload).
How can i do this ?
Thank you in advance !
Regards
Either use
if (!IsStartupScriptRegistered (key))
{
String script = "<script type=\"text/javascript\">" +
"alert('Hello World');</" + "script>";
RegisterStartupScript(key, script);
}
Or you could use the JQuery library and add the function call to the document.ready function
$(document).ready(function(){
// Add your function call here
});
I use a ContentPlaceHolder in the master-page for this purpose. This makes it possible to include specific scripts in the <head> only when you want it.
this will add onload client side event to the master page's body tag:
in the master page:
<body id="PageBody" runat="server">
in the content page:
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("PageBody");
body.Attributes.Add("onload", "doSomething();");