开发者

How do I call a Asp.Net textbox in CSS?

开发者 https://www.devze.com 2022-12-27 09:28 出处:网络
I hope this isn\'t too difficult, obviously you can call HTML tags such as fieldset, label and legends 开发者_JS百科and also textboxes. However how does one call an asp:textbox, i have tried just text

I hope this isn't too difficult, obviously you can call HTML tags such as fieldset, label and legends 开发者_JS百科and also textboxes. However how does one call an asp:textbox, i have tried just textbox, asp:textbox, input.textbox but nothing seems to work. This is something that should be really straight forward to do and I can't waste any more time figuring it out.

Thanks.


You can try input[type=text] but that will not work in IE6. Or you can create a class like .asp-textbox and set the CSSClass property of the textbox to asp-textbox which will work across browsers.

Example:

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

/*CSS*/
.asp-textbox{background-color:red;}


Understand that all of the ASP processing is done on the server, before anything gets to the user. When the user's browser is applying stylesheets, it doesn't see any of your ASP code — all it has is the HTML that's been generated by your ASP code.

So what you're trying to find out is what HTML is generated by the textbox tag. The answer is: it depends on the way the textbox is defined. If the TextMode attribute is set to "multiline", then it's rendered in HTML as a textarea element. If it's set to "password", then it's rendered as an input element of type "password". Otherwise, it's an input element of type "text".

Your best bet is probably to assign a class to your textboxes and reference that in your stylesheet.


it's an input (of type text)

it renders as <input type="text" />


The only cross browser way is to add a class to the textbox using CSSClass property and style that using the class. Also you can use the id selector. When using the id selector check for naming container also.

.test { }

<asp:textbox id="txt1" CssClass="test" runat="server" />


Try the following:

.myclass td.col1 input
{
   background-color: #D1FFC1;
}

This should work in IE also.


If I've understood you correctly, change the word "call" to "select", it's what CSS does (selects and element for styling). Use the property CssClass on the asp:Text in order to make it easily available to your CSS. Example:

.myClass { color: red; }

0

精彩评论

暂无评论...
验证码 换一张
取 消