简体   繁体   English

仍然可以在C#中检查已禁用的复选框

[英]A disabled checkbox can still be checked in C#

I have a check box in my page as follows: 我的页面中有一个复选框,如下所示:

  <asp:CheckBox ID="chkPayerCB" 
    runat="server" 
    Text="Payer Core Banking details" 
    TextAlign="Right"/>

I need to disable it on Page Load event of the page. 我需要在页面的Page Load事件上禁用它。 I wrote the following code in code behind: 我在后面的代码中编写了以下代码:

 chkPayerCB.Enabled = false;

Though the check box is disabled but it still gets checked for a moment on clicking at it and then gets unchecked. 虽然复选框已禁用但在点击它时仍会检查片刻,然后取消选中。 Though it solves my purpose but I do not want it to be checked at any cost. 虽然它解决了我的目的,但我不想不惜任何代价进行检查。

I am using VS 2008 Professional Edition (v 9.0.2). 我正在使用VS 2008专业版(v 9.0.2)。 Please can anybody guide me on this. 请任何人指导我这个。

You can use a different approach. 您可以使用不同的方法。

Set Enabled = False in the Designer . Designer设置Enabled = False

If you need to enable it under some circustances you can use Page_Load event. 如果您需要在某些情况下启用它,您可以使用Page_Load事件。

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

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