Monday, December 21, 2009

Simlest way to apply dynamic themes and skins

Introduction

It is very easy to make dynamic themes in ASP NET 2.0. In this Article I will tell you how to apply dynamic themes in C# .

Background

I was getting problem to apply dynamic themes by using session and query string methods and there I have to redirect my page again to get the desired themes. To solve this problem I have used Form to make it in simple way.

What are themes

I have not written following my own got definition from somewhere on the internet I liked it so I have added. Themes are introduced in ASP.NET 2.0 to counter the troubles faced by developers to define the layout of server controls and make them look coherent to the overall application, with minimum possible efforts. Default or Global themes are contained in a special folder inside the framework and can be declared in the source as well as class files. However, custom made themes can also be saved inside the predefined "App_Themes" folder inside ASP.NET applications, making them easier to manage and interpolate according to your needs. The essential part of themes are skin files with .skin extension. Besides skin files, a theme can be composed of styles sheets .css files as well as images for added support for the layout of the website.

Step1:

1. Add App_Themes Folder.

2. Add Themes in App_Themes lets keep its name as Theme1.

2. Add Skin File in Theme1 Folder


3. Add skinid for each skin.
      

    

Step2:



  1. Add Skin File in Theme2 Folder


  2. Add skinid for each skin 

How to apply themes 

Themes can be applied only on  PreInit or earlier events. Add All themes in dropdownlist. Get the selected Themes on Request.Form.

protected void page_PreInit(object Sender, EventArgs e)
    {      

        string strTheme = Request.Form["DropDownList1"];    
        if (strTheme == null)
        {
         strTheme= "Theme1";
         Page.Theme = strTheme;
        }
        else
        {
            Page.Theme = strTheme;
        }        
       
    }

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            DropDownList1.Items.Add("Theme1");
            DropDownList1.Items.Add("Theme2");
        }

    }  


No comments:

Post a Comment