Search code examples
jqueryasp.netuser-controls

How to run ClientScript in User Control?


I am using the code:

   ClientScript.RegisterStartupScript(typeof(Page), "message", message);

This code works fine in an ASP.NET page but does not in a UserControl. I need to use this functionality in UserControl.


Solution

  • You could try:

        string script = "<script language='JavaScript'>alert('hello');</script>";
        Page.RegisterStartupScript("myscript", script);
    

    or

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", "<script>alert('Hello.')</script>", false);