CSS to Themes in ASP.NET using VB.NET
Cascading Style Sheets (CSS) load pages faster and leaner, this is main advantage of CSS file. CSS is alternative of skins, to change the appearance of ASP.Net control and HTML element using CSS file. If you add CSS file in Theme folder than it’s automatically applied on all pages of your application. CSS used to style HTML element. ASP.Net render
Cascading Style Sheets (CSS) load pages faster and leaner, this is main advantage of CSS file. CSS is alternative of skins, to change the appearance of ASP.Net control and HTML element using CSS file. If you add CSS file in Theme folder than it's automatically applied on all pages of your application. CSS used to style HTML element. ASP.Net render HTML this is the reason that CSS file easily apply on ASP.Net control.
Suppose you change a few property of one label control, whenever you request page only additional properties must be rendered to the browser but in case of SKIN file first all label property change in application then after that label rendered to the browser, so we can say CSS faster as compare to SKIN file.
Using CssClass attribute of ASP.Net control you can apply any style by target any control. In this example, I have applied different appearance on all controls using style sheet. First must be look blue and second label must be look green. One interesting thing, Look at the output in figure3 you will notice that password is displaying in white color because I set its color property white in CSS file.
Step1: Add Theme by adding a new folder to a special folder in your root application. Right clicking on project in Solution Explorer drag your mouse on Add Asp.Net Folder you will see Theme option in list and click on that. See the below figure to know how to add theme in application. Different themes should be added on different folder in App_Themes folder. You can add multiple subfolders in Theme folder. A theme file contains different type of files but Skin and CSS file is most important file in Theme folder.
Step 2: After adding Theme Folder add CSS file on that folder, right click on theme folder than click on Add New Item and select StyleSheet file from dialog box.
<%@ Page Language="C#" StylesheetTheme="Theme1" AutoEventWireup="true" CodeFile="LoginPage.aspx.cs" Inherits="LoginPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
<asp:Label ID="Label1" CssClass="labl" runat="server" Text="User Name"></asp:Label>
<asp:TextBox ID="TextBox1" CssClass="txtbox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" CssClass="labl2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox2" CssClass="txtbox2" TextMode="Password" runat="server"></asp:TextBox>
<asp:Button ID="Button1" CssClass="btn" runat="server" Text="Sign In" />