5

I want to add style in ASP.NET textbox control. I couldn't 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 don't want to do it with CSS class.

5 Answers 5

9

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" />
6

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.

1
  • also can use [type=text] Feb 17, 2014 at 15:11
3

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.

2

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"

0
0
input[type=text]

but won't work in IE.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.