Register javascript inside User Control using C#

mehul9595 picture mehul9595 · Jan 21, 2011 · Viewed 15.2k times · Source

I want to call javascript function from User Control using C#. For that i am trying to use

ScriptManager.RegisterStartupScript(this, typeof(string), "alertbox", "javascript:ShowPopup('Select a row to rate');", true); 

but it is not working for me. This works fine on the page. Can some one help me out how can i call javascript function at runtime using C#.

Thanks,

Answer

zavaz picture zavaz · Jan 21, 2011

Try this.GetType() instead of typeof(string):

ScriptManager.RegisterStartupScript(this, this.GetType(), "alertbox", "ShowPopup('Select a row to rate');", true);