Themes and skins in ASP.NET

In this article we will learn how to apply themes and skins in ASP.NET.
  • 2086

In this article we will learn how to apply themes and skins in ASP.NET.

Themes

  1. A theme is a folder containing some files with .skin extension.
  2. Each skin file will have the same name as control's class name.
  3. All the themes must be placed under special folder App_Themes.
  4. Add this folder from Solution Explorer -> Project -> add-> new items-> skin file.

Creating a skin for a control

  1. Create a new blank form.
  2. Add the control for which style is to be created.
  3. Add the properties.
  4. Cut and paste the control to corresponding skin file.
  5. Remove the ID attribute of the skin.

In this article we will learn how to apply themes and skins in ASP.NET

For example:

Drag two textbox and one button on the form named themetest.

theme1.gif
 

Figure 1.

Add themes folder containing some files with .skin extension.

theme2.gif
 

Figure 2

Now we apply themes for button control and textbox control named first and second.

theme3.gif
 

Figure 3.

Now for first skin files add the following code.in.

Button code

<asp:Button  runat="server" Text="Button" BackColor="#003399"

        BorderColor="#3366FF" BorderStyle="Dotted" Font-Bold="True" ForeColor="White" />

 

Textbox code

asp:TextBox  runat="server" BackColor="#003399"

  BorderColor="#3366FF" BorderStyle="Dotted" Font-Bold="True" ForeColor="White"></asp:TextBox>

 
 

Now for second skin files add the following code. 
 


 

Button code


 

<asp:Button  runat="server" Text="Button" BackColor="#003366"

        BorderColor="#CC3300" BorderStyle="Groove" BorderWidth="4px" Font-Bold="True"

        ForeColor="Yellow"/>


 

Textbox code

 

<asp:TextBox  runat="server" BackColor="#003366"

        BorderColor="#CC3300" BorderStyle="Groove" BorderWidth="4px" Font-Bold="True"

        ForeColor="Yellow"></asp:TextBox>

 

Applying the theme on some page

 

-Use Theme attribute of Page directive or Theme property of Page class.

 

protected void Page_PreInit(object sender, EventArgs e)

        {

            Page.Theme = "Second";

        }

Or

 
 

Page Language="vb" AutoEventWireup="false" CodeBehind="Themestest.aspx.vb" Inherits="WebApplication28.WebForm1" theme="first" %>


 

Now save and run the application for First skin file.

theme4.gif
 

Figure 4.
 

Now applying second  replace only second place of first. such as

Page Language="vb" AutoEventWireup="false" CodeBehind="Themestest.aspx.vb" Inherits="WebApplication28.WebForm1" theme="Second" %>
 

And again run the application for second skin file.

theme5.gif
 

Figure 5

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.