Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS and ASP.NET controls

I've noticed when trying to apply the 'style' attribute to an asp:TextBox control, for example or when attempting to use a css class to apply a style, it doesn't take. I have to specifically set the attribute. For instance:

 <asp:TextBox runat="server" ID="DescriptionTextBox" BackColor="#F7FCFF" /> // Works

 <asp:TextBox runat="server" ID="DescriptionTextBox" CssClass="textbox" />  // Doesn't work
 <style type="text/css">
 .textbox
 {
     background-color: #F7FCFF;
 }
 </style>

I know this is a simple question, but can someone kindly shed some light on it for me?

Thank you

like image 926
Jesse Roper Avatar asked Aug 24 '11 19:08

Jesse Roper


2 Answers

Don't get too confused over what an asp control actually is. In fact all it does is generate HTML, which is what the CSS is then applied to.

Your second example with CssClass should work, but instead of debugging by looking at your aspx you really need to check out the HTML (using your browsers version of the developer tools such as Firebug will show you what styles are being applied).

like image 60
m.edmondson Avatar answered Oct 31 '22 02:10

m.edmondson


The text box control probably generates either style attribute with background colour or uses more specific CSS rule.

Check the html generated and use FireBug to see which CSS rules are applied / overridden.

like image 24
Jakub Konecki Avatar answered Oct 31 '22 00:10

Jakub Konecki