tags:

views:

48

answers:

3

window.execscript("mycode","javascript") is not working when tried to execute,also not giving any exception at that point.Any suggestion is welcome.

Thanks in Advance

A: 

When you are working in an asp.net environment you can use:

ClientScript.RegisterStartupScript(this.GetType(), "myscript", "the script", true);

More info can be found here: http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx

Sem Dendoncker
A: 

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.

Danny Chen
A: 

If you are interested in running JavaScript on the server, then see this related question http://stackoverflow.com/questions/2719748/execute-javascript-on-iis-server

James Westgate