javascript 禁用 asp.net 按钮回发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10659738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable an asp.net button postback
提问by jams
I tried to disable an asp.net button but failed. The error:
我试图禁用一个 asp.net 按钮但失败了。错误:
Compiler Error Message: CS1501: No overload for method 'btnUnlock_Click' takes '0' arguments
Source Error:
源错误:
Line 99: <asp:Button ID="btnUnlock" runat="server" Text="Unlock User" Visible="False" OnClick ="btnUnlock_Click()" />
And
和
protected void btnUnlock_Click(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser(userName);
user.UnlockUser();
}
Thanks.
谢谢。
回答by jams
Use OnClientClick="return false;"
to disabled postback. You can try this
使用OnClientClick="return false;"
已禁用回发。你可以试试这个
<asp:button runat="server".... OnClientClick="return false;" />
In C# you can disable button by
在 C# 中,您可以通过以下方式禁用按钮
btnUnlock.IsEnabled = false;
回答by Jacob
Two problems here:
这里有两个问题:
OnClick="btnUnlock_Click()"
This syntax is incorrect. To set up your server-side click handler, write it like this:
此语法不正确。要设置您的服务器端点击处理程序,请按如下方式编写:
OnClick="btnUnlock_Click"
Also, your question title doesn't seem to relate to this code at all. If you're wanting to know how to disable the server-side click handling client-side, you can add a client-sideclick handler, like this:
此外,您的问题标题似乎与此代码完全无关。如果您想知道如何禁用服务器端点击处理客户端,您可以添加一个客户端点击处理程序,如下所示:
OnClientClick="return false;"
...or some custom client-side function. To disable it server-side, simply don't add the OnClick
attribute.
...或一些自定义客户端功能。要在服务器端禁用它,只需不要添加该OnClick
属性。