How to run ClientScript in User Control?

I am using code

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

this code works fine on the asp.net page, but not in UserControl. I need to use this function in UserControl.

+3
source share
2 answers

You can 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);
+10
source

I use this in my usercontrols: Page.ClientScript.RegisterStartupScript (typeof (Page), "message", message)

+1
source

All Articles