简体   繁体   English

通过使用Firebug删除“ disabled”属性在C#中启用按钮

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

I have a question about disable button (C#) that I need your help. 我对禁用按钮(C#)有疑问,需要您的帮助。

in Asp.net (C#), disable the button code: 在Asp.net(C#)中,禁用按钮代码:

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

The generated HTML: <input type="button" disabled="disabled"> 生成的HTML: <input type =“ button” disabled =“ disabled”>

The button is disabled until I use firebug and remove the 'disabled' property and change the type property to submit ( <input type="submit"> ) then user can click on btn and it can perform btn_click method(postback). 在我使用Firebug删除'disabled'属性更改type属性以提交<input type =“ submit”> )之前,该按钮一直处于禁用状态,然后用户可以单击btn并可以执行btn_click方法(回发)。

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 CommandName== "disable" then stop the function but it is very messy. 我尝试使用CommandName(禁用,启用)来标记禁用按钮,并在btn_click方法内部,我检查CommandName ==“ disable”,然后停止该功能,但是非常混乱。

Thanks for your help. 谢谢你的帮助。
Van

Client can remove the Disabled attribute but cannot change the control ViewState. 客户端可以删除Disabled属性,但不能更改控件的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 您可以在btn_click ..中判断按钮的状态,然后进行一些工作

@bystander is right. @bystander是正确的。 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. 您不能依靠客户提供100%的傻瓜证明,这就是原因。

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. 隐藏实际上根本不会将控件呈现给客户端。

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

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