javascript execution from c#
window.execscript("mycode","javascript") is not working when tried to execute,a开发者_Go百科lso not giving any exception at that point.Any suggestion is welcome.
Thanks in Advance
If you are interested in running JavaScript on the server, then see this related question Execute javascript on IIS server
You know we can't execute javascript from code behind at server side. What we can do is to register a java script and make it run after the page is rendered at client side. Here is an example:
//Page_Load method in Default.aspx.cs, notepad code
string js = "<script type='text/javascript'> alert('hello world!'); </script>";
ClientScript.RegisterStartupScript(this.GetType(),"helloworld",js);
Here I use a string directly, usually you can generate a complex javascript with StringBuilder. RegisterStartupScript will add the js to the page and execute it when the script is loaded.
精彩评论