简体   繁体   English

禁用asp.net按钮回发

[英]Disable an asp.net button postback

I tried to disable an asp.net button but failed. 我试图禁用asp.net按钮但失败了。 The error: 错误:

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. 谢谢。

Use OnClientClick="return false;" 使用OnClientClick="return false;" to disabled postback. 禁用回发。 You can try this 你可以试试这个

<asp:button runat="server".... OnClientClick="return false;" />

In C# you can disable button by 在C#中,您可以禁用按钮

btnUnlock.IsEnabled = false;

IsEnabled Property MSDN link IsEnabled属性MSDN链接

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-side click 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属性即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM