簡體   English   中英

如何在Web用戶Control ascx中調用javascript函數

[英]how to call javascript function in Web user Control ascx

我在test.ascx ASP控件上有以下代碼:

  function mute() {       
        var button_mute = document.getElementById('<%= btnRequestCompanyCheck.ClientID %>');
        button_mute.style.display = "none";
        alert("x");

    }

我如何從Code后面調用mute()(test.ascx.cs),我正在嘗試以下所有列表,沒有人為我工作。 我應該在Asp.net Control上使用哪一個?

ScriptManager.RegisterOnSubmitStatement(this, this.GetType(), "test", "mute()");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", "mute()", true);
ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "mute()", true);
ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "mute()", true);
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction","mute()", true);

你試過這個嗎?

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return mute();" />

這是javascript代碼。

<script type="text/javascript">
function mute() {
    alert("Muted");

    return false;
}
</script>

這是替代背后的代碼

Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "mute()", true);

你必須在父ScriptManager上注冊ScriptManager

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

你可以用之后

 Page.ClientScript.RegisterStartupScript(GetType(), "indexonchange", "OnIndexChange();", true);

嘗試這個:

ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "javascript:mute();", true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM