如何在Web用户控件中调用javascript函数
本文关键字:调用 javascript 函数 控件 用户 Web | 更新日期: 2023-09-27 18:06:48
我有下面的代码测试。ascx ASP Control:
function mute() {
var button_mute = document.getElementById('<%= btnRequestCompanyCheck.ClientID %>');
button_mute.style.display = "none";
alert("x");
}
我如何从代码后面(test. asx .cs)调用mute(),我正在尝试下面列出的所有方法,没有人为我工作。我应该在Asp.net控件上使用哪一个?
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
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
之后可以使用
Page.ClientScript.RegisterStartupScript(GetType(), "indexonchange", "OnIndexChange();", true);
try this:
ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "javascript:mute();", true);