aqsa
aqsa

Reputation: 31

styling asp controls by using stylesheet

i want to ask how i can apply style on asp tags by using stylesheet???

For example i want to style a asp button control like following

  <asp:Button ID="btnhme" runat="server" Text="Home" Width="145px" 
         BackColor="#3399FF" />  

i know i can style it by using its properties but i want that if i have 10 buttons in my page then same style is apply to all buttons automatically and i have to do it for my all pages buttons and labels controls and i cannot set properties for all separately

is there is a solution by using stylesheet and if not by using stylesheet then what should i do that the style apply to all button controls and textbox,labels controls also

<asp:Label ID="lbllogin" runat="server" Text="LogIn Here"></asp:Label>
<asp:TextBox ID="txtuser" runat="server"></asp:TextBox>

please guide me how i can solve this issue Thanx :)

Upvotes: 2

Views: 3833

Answers (3)

IUnknown
IUnknown

Reputation: 22478

You can register default skin for server controls with desired properties responsible for styling. Look at this article: How to: Apply ASP.NET Themes

If the page theme does not include a control skin that matches the SkinID property, the control uses the default skin for that control type.

Upvotes: 1

Taylor Brown
Taylor Brown

Reputation: 1775

well you could set default css for each element, this would automatically cause every control of this type to take on this css:

input[type=text] {
    //styling
    color:blue;
}

label {
    //styling
    color:blue;
}

or you could come up with your own css class and just attach it to the elements you want:

.myTextClass
{
        //styling
        color:blue;
}

.myLabelClass
{
        //styling
        color:blue;
}

then attach the class using the CssClass property:

<asp:Label ID="lbllogin" runat="server" Text="LogIn Here" CssClass="myLabelClass"></asp:Label>
<asp:TextBox ID="txtuser" runat="server" CssClass="myTextClass"></asp:TextBox>

Upvotes: 1

Joe Ratzer
Joe Ratzer

Reputation: 18569

Add the CssClass property to the Button control, for example, and add a corresponding class to the CSS file.

aspx

<asp:Button ID="btnhme" runat="server" Text="Home" Width="145px" BackColor="#3399FF" CssClass="my-buttons" />  

CSS

.my-buttons { background-color:#3399FF; }

Upvotes: 1

Related Questions