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
Post a Comment