简体   繁体   English

如何在Web用户Control ascx中调用javascript函数

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

I have the following Code on test.ascx ASP Control : 我在test.ascx ASP控件上有以下代码:

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

    }

How I can call mute() from Code behind (test.ascx.cs), I am trying all of below list, no one is working for me. 我如何从Code后面调用mute()(test.ascx.cs),我正在尝试以下所有列表,没有人为我工作。 Which one should I used on Asp.net Control ? 我应该在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);

Did you tried this? 你试过这个吗?

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

And here is the javascript code. 这是javascript代码。

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

    return false;
}
</script>

Here is the code behind alternative 这是替代背后的代码

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

you have to register ScriptManager on parent control like 你必须在父ScriptManager上注册ScriptManager

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

after you can use, 你可以用之后

 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