CSS and ASP.NET controls

I noticed that when trying to apply the style attribute to an asp: TextBox control, for example, or when trying to use the css class to apply a style, this is not required. 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 shed light on it for me?

thanks

+4
source share
4 answers

Don't be too embarrassed about what asp controls actually have. In fact, all he does is generate HTML that is then applied to CSS.

The second example with CssClass should work, but instead of debugging, looking at your aspx, you really need to check the HTML (using the browser version for developer tools like Firebug will show you which styles are applied).

+5
source

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

Check out the generated html and use FireBug to see which CSS rules apply / override.

+2
source

Everything looks right. Make sure you bind your stylesheet between your headers, or if you choose the inline tag’s route, they should also be between the head.

 <html> <head> <link href="StyleSheet.css" type="text/css" rel="stylesheet" /> </head> <body>.... 

OR

 <html> <head> <style type="text/css"> .textbox { background-color: #F7FCFF; } </style> </head>.... 

Remember that HTML does not have a TextBox control, so if it does not give you a property (e.g. asp.net), you should have this CssClass that you used. Also, if you use the format in your example, as a comparison, this is your problem. See my second block of code where the style should be.

Hope that helps

Tony

+2
source

You can also do something like DescriptionTextBox.style.add ("background-color", "#fff") in your code.

+2
source

All Articles