how to change multiple asp.net textbox or labels or tags in different style with CSS or CSSClass or in C#?

<asp:TextBox ID="givennametb" runat="server" BackColor="White" ForeColor="Black" Width="145px" CssClass="textbox"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="familynametb" runat="server" BackColor="White" ForeColor="Black" Width="145px"></asp:TextBox>

I wrote this piece of code. Now I want to change bordercolor of givennametb textBox to blue and familynametb to red.

I do not want to do it inline withBorderColor:"blue/red". I want to use CSS/CSSClass. I am using C# with ASP.NET. If I do cssClass="textbox" and try to change in style, all tags are changing to same color. I want to change separately.

Upvotes: 0

Views: 399

Answers (2)

Carlos Bolivar
Carlos Bolivar

Reputation: 317

Remember, ASP.Net is going to render the control ASP:Text for the web browser in a <Input type="text"> of a <form> HTML, so you can use a CCS Selector with the Id of control to modify the border color of textBox.

input#givennametb{
       border:1px solid blue;
    }

 input#familynametb{
       border:1px solid red;
    }
<input id="givennametb" type="text" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="familynametb" type="text" />

Upvotes: 1

Carlos Bolivar
Carlos Bolivar

Reputation: 317

input.textbox#givennametb{
       border:1px solid blue;
    }

 input.textbox#familynametb{
       border:1px solid red;
    }
<input id="givennametb" type="text" class="textbox" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="familynametb" type="text" class="textbox" />

Upvotes: 0

Related Questions