tags:

views:

272

answers:

5

I want to add style in asp.net textbox control. I could'nt find textbox element in elements list. I can put style in all input controls using the below code in css.

input { backgroud-color:black; }

but this changes the background color of all input controls like buttons, radiobox etc.

I want to do it exclusively with textbox,I dont want to do it with css class.

A: 
input[type=text]

but won't work in IE.

Use a class name instead and apply that class to your text elements.

rahul
+1  A: 

This will do it:

input[type=text]

Though it might not work in all browsers (e.g. IE). The only way to ensure that would be to add a class or put it inside a span element.

richeym
It's also working in IE, Thanks.
vaibhav
it will not however work in IE6 or below
Aaron
A: 

Not 100% sure if this is what you're looking for but you can put CssClass="myTextBoxStyle" in the ASP.NET server-side tag and then define a class called .myTextBoxStyle in your stylesheet. It will then only affect textboxes where you've added CssClass="myTextBoxStyle"

Nestor
+2  A: 

It would be easier to put css class on those textboxes (input type="text")

<style>
   .textbox { /*some style here */ }
</style>

<input type="text" class="textbox" /> or
<asp:TextBox id="someid" runat="server" CssClass="textbox" />
jerjer
A: 

A 100% cross browser, that works in IE6, is to make use of asp.net themes and skins. Create a skin file in the app_themes directory and add the following line:

<asp:TextBox runat="server" CssClass="textbox" />

This will then apply the CSS class "textbox" to every textbox in your site, assuming you have corresponding CSS and theme references.

Dan Diplo