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,
Try this.GetType() instead of typeof(string):
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertbox", "ShowPopup('Select a row to rate');", true);
The following is taken from working code, showing script being registered to fire from an asynchronous postback in an UpdatePanel
.
ScriptManager.RegisterStartupScript( this.upnl, this.upnl.GetType(), Guid.NewGuid().ToString(), "alert('test');", true );
If your code is not executed from inside an UpdatePanel
, it still should not be typeof(string)
; you should use the type of some container (typically the control itself).
Type: The type of the client script block. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With