如何在用户控件中运行ClientScript?

时间:2012-04-17 12:02:40

标签: jquery asp.net user-controls

我正在使用代码

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

此代码在asp.net页面中正常工作,但在UserControl中不起作用。我需要在UserControl中使用此功能。

2 个答案:

答案 0 :(得分:12)

你可以尝试:

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

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

答案 1 :(得分:1)

我在我的usercontrols中使用它: Page.ClientScript.RegisterStartupScript(typeof(Page),&#34; message&#34;,message)