-1

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

sunny
  • 1
  • 4
    Welcome to Stack Overflow! Unfortunately, your question does not contain much detail and it will be hard to answer unless you can provide some more context. – Dean Harding Jun 22 '10 at 07:09

2 Answers2

1

If you are interested in running JavaScript on the server, then see this related question Execute javascript on IIS server

Community
  • 1
  • 1
James Westgate
  • 11,306
  • 8
  • 61
  • 68
0

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.

Cheng Chen
  • 42,509
  • 16
  • 113
  • 174