7

I have this textbox

<asp:TextBox ID="tbid" runat="server" class="form-control"></asp:TextBox>

form-control is a bootstrap class so the textbox gets the bootstrap look, if I disable the control from code using

tbid.Enabled = false;

the textbox loses the form-control class, after inspected the textbox I found out that it gets replaced by the aspNetDisabled class.

how I can prevent the change of class I want to keep the disabled button with the bootstrap look even if it is disabled.

YHAM
  • 79
  • 2
  • 11

3 Answers3

11

You can do this:

// Code
tbid.Attributes["disabled"] = "disabled";
YHAM
  • 79
  • 2
  • 11
Farzin Kanzi
  • 3,380
  • 2
  • 21
  • 23
  • The same does not work on asp.net radiobutton. Could you please tell if you know – Sid Jul 24 '22 at 17:03
  • You can use this for radio button: `tbid.InputAttributes.Add("disabled", "disabled");` – Farzin Kanzi Jul 24 '22 at 20:14
  • Thanks @Farzin. This is the only way to disable my asp.button in bootstrap. How can I enable it later on? – Petronius Jul 28 '22 at 13:44
  • @Petronius You can enable it later in client side, by removing the disabled attribute by javascript or Jquery. https://stackoverflow.com/questions/11719961/javascript-remove-disabled-attribute-from-html-input – Farzin Kanzi Jul 29 '22 at 07:25
5

I was having similar issues, but strangely only on some buttons on my page, so this piqued my curiosity...

Try using the CssClass instead of Class attribute, and it will work as expected.

<asp:Button id="Button1" runat="server" CssClass="btn btn-warning" Text="My Button" OnClick="Button1_Click" />
AaronC
  • 51
  • 1
  • 6
-2

'on load write tbid.Attributes("disabled")= "disabled"

  • 2
    Besides missing code formatting, this already has been answered in 2017 by [Farzin Kanzi](https://stackoverflow.com/a/41991422/7831383) – Rafalon Mar 28 '18 at 09:51
  • While this might be an asnwer to OPs question, its recommended to add more information on your suggested solution... – Aditya Mar 28 '18 at 09:54