代码之家  ›  专栏  ›  技术社区  ›  Peter Evjan

无法在ASP上执行javascript。NET用户控件

  •  1
  • Peter Evjan  · 技术社区  · 17 年前

    protected void btnSave_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(btnSave, GetType(), "uniqueID", "alert('hello');", true);
    }
    

    以及

    Page.ClientScript.RegisterStartupScript(GetType(), "uniqueID", "alert('hello');", true);
    

    但似乎没有什么对我有效。该控件位于ASPX页面中的RadAjaxPanel(telerik)中。

    我错过了一些明显的东西。有什么想法吗?

    编辑: 据我所知,javascript没有注入到html源代码中。我在html中查找ID和实际的警报语句。

    4 回复  |  直到 17 年前
        1
  •  1
  •   Canavar    17 年前

    参数:

    Page.ClientScript.RegisterClientScriptBlock(typeof(MyPage), 
        "myPostBackScript", script, true);
    

        2
  •  1
  •   Peter Evjan    17 年前

    啊,问题出在Telerik RadAjaxPanel上。我只需将EnableOutsideScripts设置为true,如下所示:

    <telerik:RadAjaxPanel ID="ajaxpanel" runat="server" LoadingPanelID="ajaxLoadingPanel" EnableOutsideScripts="true">
    

    ScriptManager.RegisterStartupScript(btnSave, GetType(), "uniqueID", "alert('hello');", true);
    
        3
  •  0
  •   Dror Big McLargeHuge    17 年前

    <form runat="server"

        4
  •  0
  •   Community Mohan Dere    6 年前

    如果从点击按钮事件开始,你会打电话吗?无论你使用什么控件,都要确保你是从客户端事件调用js的

    另外,看看 this 对于想法

    编辑

    SO question

    EDIT2

    the last post on this page

    推荐文章