简体   繁体   中英

Disable an asp.net button postback

I tried to disable an asp.net button but failed. 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;" to disabled postback. You can try this

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

In C# you can disable button by

btnUnlock.IsEnabled = false;

IsEnabled Property MSDN link

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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