How to call a JavaScript function from C# code
I need to call a jav开发者_如何学编程ascript function from C# code after page Load, or is it there any way that I can do this on .aspx page itself??
Thanks
try with RegisterStartupScript
E.g:
RegisterStartupScript("Msg1", "<script language='javascript'> alert('Hello World') </script>");
You can use this,
Page.ClientScript.RegisterStartupScript(Page.GetType(), "script",
"urfunction()", true);
string script = "..." // your script here without <script> tags
ClientScript.ClientScript.RegisterStartupScript(GetType(), "key", script, true)
Also if you want to use it directly from the .aspx you can use jquery
$(document).ready( function() {
//... your script here
});
精彩评论