Sunday, August 24, 2008

Calling Javascript from an UpdatePanel

You've probably used ClientScript.RegisterStartupScript in your ASP.NET application and it works just fine. However, if you try it within an UpdatePanel control, you would notice that it simply doesn't execute.

The solution to this problem is to use ScriptManager.RegisterStartupScript instead. You can call it like so:
ScriptManager.RegisterStartupScript(updatePanel1, updatePanel1.GetType(), "key", "alert('My script');", true);

7 comments:

Aditya said...

Nice one. Saved me tons of time.

Nitin R.K. said...

Always glad to be of service!

immi said...

Awesome. You are legend

Mambo Joel said...

I owe you an afternoon.

Sachin Navale said...

Thanks a ton nitin.

mnh said...

Thanks for the solution :)

Angelo said...

look at this link, you might find an answer:
http://www.systemdeveloper.info/2014/01/fileupload-control-in-update-panel.html
or in
http://www.systemdeveloper.info/2014/02/how-do-i-add-javascript-updatepanel-in.html