asp.net - How can I call javascript method from my aspx.cs file -


I have a javascript method that I need to call from the aspx page at page load time. Javascript modes are client-side methods, so you can not call them in your server side code.

But if you are looking for a method to call your method on page load, call your method on the script tag and write it in your ASPX page:

  & Lt; Body & gt; & Lt; Script language = "javascript" & gt; MyMethod (); & Lt; / Script & gt; & Lt; / Body & gt;  

Or you can register your script code from behind:

  Protected Zero Page_load (Object Sender, EventArgus E) {string script = "MyMethod ();"; If (! This.Page.ClientScript.IsClientScriptBlockRegistered ("myPostBackScript")) {this.Page.ClientScript.RegisterClientScriptBlock (type (MyPage), "myPostBackScript", script, true); }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -