0

I am working on a webpage and at some point I need to disable a asp:button.

This page uses a css file that has the following class:

.pagerLinkDisabled
{
    display: none;
}

So every time I set a button to disabled .net renders it with class="pagerLinkDisabled" and the button is not displayed...

At pageload I tried this:

myButton.Enabled=false;
myButton.Style.Add("display","static");

How can I work around this problem without changing the css file?

Thanks :)

Edit:

To clarify:

  • The button is being rendered but when enabled is set to false the framework is adding class="pagerLinkDisabled" to the input tag.

  • This class is defined at a css file that I cannot change.

Edit2:

My button is defined as such:

<asp:Button runat="server" ID="myButton" Text="mytext" Enabled="false" />

The html that is being rendered is:

<input type="submit" name="ctl00$ContentPlaceHolder$ctl00$myButton" value="mytext" id="ctl00_ContentPlaceHolder_ctl00_myButton" class="pagerLinkDisabled" />
Sergio
  • 8,125
  • 10
  • 46
  • 77

5 Answers5

2

I am not sure but try at page load:

myButton.Visible = true;
  • Nice try but no... when visible = false the button is not rendered, in this case it is being rendered but being keep "unvisible" with the display:none from the css – Sergio May 12 '09 at 16:03
1

Why not just change the class name on the button?

JonoW
  • 14,029
  • 3
  • 33
  • 31
  • Also tried that. If I define a cssclass for the button the input tag is rendered with the class attributes and assumes the first one.. – Sergio May 12 '09 at 16:04
1

Have you tried something like this:

myButton.Attributes.Add("Style","display:block !important");
Gavin Miller
  • 43,168
  • 21
  • 122
  • 188
  • Doing that makes the button appear, but enabled... I have placed the line just bellow myButton.Enabled = false – Sergio May 12 '09 at 16:09
1

Can you not just edit the HTML Source so that the button does not use that class?

Or is it defines at a higher level within with HTML? e.g. At the BODY tag.

kevchadders
  • 8,335
  • 4
  • 42
  • 61
1

Edit This works for me.

myButton.Style["display"] = "block !important";
myButton.Style["disabled"] = "disabled";
Jab
  • 13,713
  • 2
  • 42
  • 48
  • Check for the update, it works for me. I would prefer to just update the CSSClass attribute on the button if at all possible though. – Jab May 12 '09 at 17:07
  • Then something else is going on we can't see. Does your input element have the disabled='disabled' attribute? Something else must be conflicting, even the single lb.Style["display"] = "block !important"; works fine on a blank page with a single CSS class defined. Add what the markup is putting to the question and I might be able to help more. – Jab May 12 '09 at 17:36
  • I'm not sure what framework you are working with. ASP does not add that CSS Class by default, maybe something else is conflicting with it. – Jab May 13 '09 at 14:28