I added to the main page my script "myscript.js". Then on the content page, I would like to load myscript () at startup (body onload).
How can i do this?
Use
Page.RegisterStartupScript
if (!IsStartupScriptRegistered (key)) { String script = "<script type=\"text/javascript\">" + "alert('Hello World');</" + "script>"; RegisterStartupScript(key, script); }
Or you can use the jQuery library and add a function call to the document.ready function
http://jquery.com/
$(document).ready(function(){ // Add your function call here });
I use ContentPlaceHolderthe home page for this purpose. This allows you to include specific scenarios <head>only when you want it.
ContentPlaceHolder
<head>
onload :
:
body id="PageBody" runat="server" in the content page: HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("PageBody"); body.Attributes.Add("onload", "doSomething();");`
onLoad.
Source: https://habr.com/ru/post/1749028/More articles:git output conflict results - gitVisual C # 2010 Express saves file descriptor after debugging - c #Eclipse IDE for C / C ++ Developers Compiles Question - c ++Import Python modules without installing - Sybase ASE - pythonJava applets and javascripts - javascriptParsing timestamp with Python2.4 - pythonDoes Nhibernate support Sybase? - sybaseSetting the service url at runtime - c #TinyMCE or HTML5 contentEditable attribute? - html5create jQuery plugins to automatically create page load numbering - jquery-pluginsAll Articles