by disabling a button this loses the bootstrap look


I have this textbox

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

form-control is a bootstrap class for the textbox to have the bootstrap look, if I disable the textbox from code using

tbid.Enabled = false;

the textbox loses the look of botstrap, after inspecting the code I saw that it is replaced by the aspNetDisabled class.

As I can prevent this from happening I want the button to keep the bootstrap look still disabled.

asked by YHAM 02.02.2017 в 00:50

3 answers


The easiest way I found to do it was by putting this


.Attributes ["disabled"]="disabled"

instead of this


.Enabled = false;

answered by 04.02.2017 в 17:48

What do you think about putting in your file CSS class aspNetDisabled and in it you put the css you want (equal to the class form-control ), but to each label you assign !important at the end. Example:

Your class form-control current in your file CSS :

.form-control {
    color: red;
    text-align: center;

Now you put in your same file CSS the class aspNetDisabled :

.aspNetDisabled {
    color: red !important;
    text-align: center !important;

The above will cause the css of the class to be replaced by the one you want.

I hope it works for you.

answered by 02.02.2017 в 16:27

The correct Asp.Net attribute to set in your control is CssClass .

The attribute that you have set class , despite being a valid attribute, interferes with the Asp.Net engine when rendering your control and does not mix Asp.Net's own "class" attribute with yours.

If that does not solve the problem, you can set the default class disabled for the Asp.Net server controls in the Global.asax in the method that runs when you start the app:

void Application_Start(object sender, EventArgs e)
    WebControl.DisabledCssClass = string.empty;
answered by 03.02.2017 в 12:25