简体   繁体   中英

enable button in C# by removing 'disabled' property using firebug

I have a question about disable button (C#) that I need your help.

in Asp.net (C#), disable the button code:

    Button btn = new Button();
    btn.click += new EventHandler(btn_click);
    btn.Enabled = false;
    btn.UseSubmitBehavior = false;

The generated HTML:

The button is disabled until I use and and ( ) then user can click on btn and it can perform method(postback). )之前,该按钮一直然后用户可以单击btn并可以执行方法(回发)。

How could we prevent this issue? I try to use CommandName (disable, enable) to mark disable button and inside btn_click method, I check if then stop the function but it is very messy. 然后停止该功能,但是非常混乱。

Thanks for your help.
Van

Client can remove the Disabled attribute but cannot change the control ViewState. On server side you can do that:

protected void btn_Click(object sender, EventArgs e)
{
     if (btn.Enabled)
     {
           // do something         
     }
}

<asp:Button ID="btn" runat="server" Enabled="false" OnClick="btn_Click" Text="Test" />

You can't control your users' behavior.What you need to do is handle these things in server-side..

you can judge the button's status in btn_click.. and then do some work

@bystander is right. You need to check on the server whether that condition is correct. You can't rely on the client being 100% fool proof, and that's the exact reason why.

Can you hide the control instead, and reenable it on some future postback? Hiding doesn't actually render the control to the client at all.

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