.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share

 Subscribe to Articles

Themes in Asp.Net 2.0

Posted By :Deepika Haridas      Posted Date :01/02/2010   Points :25   Category: ASP.NET    URL: http://www.angeldeeps.blogspot.com

A theme is a collection of settings that define the look of controls and web pages (Asp.Net). Themes are applied across all the pages in a Web application to maintain a consistent appearance.
    


THEMES IN ASP.Net 2.0 :

A theme is a collection of settings that define the look of controls and web pages. Themes are applied across all the pages in a Web application to maintain a consistent appearance.

A theme is a file with .skin extension that contains property settings for individual controls such as a Button, textbox or a Label control. You can either define skins for each control in different skin files or you can define skins for all the controls in a single file.

Themes are of two types -

  1. Page  - A theme which can be applied to only a single page of the website is called a Page theme.

A Page theme contains the control skins, style sheets, graphic files, and other resources inside the subfolders of App_Themes folder. For different themes separate subfolders are created in the App_Themes folder.

  1. Global - A global theme is a theme that is applied to all the webpages of any website. It includes property  settings, style sheet settings, and graphics. This theme allows you to maintain all the websites on the same web server and to define the same style for all the pages of all websites.

Global themes are placed in the Themes folder and can be accessed by an website.

Steps to create themes :

  1. Right click on Web application's name in solution explorer and first select Add ASP.Net Folder option -> Themes
  2. This will add folder named App_Themes with one subfolder named Theme1 inside it.
  3. Right click Theme1 folder --> Add New Item --> Skin File (I have named it as Theme.skin). Add following code in it.   
    <asp:Label runat="server" width="300px" height="25px" font-bold="true" font-size="large" forecolor="white" backcolor="Black" />
    <asp:TextBox runat="server" forecolor="Red"  font-bold="true"font-size="Medium" font-italic="True"/>
    <asp:Button runat="server" forecolor="white" backcolor="Black" />

    1. Now create a Default.aspx page to test out. (Below is the sample screen)
                   
    1. Add reference to Theme1.skin file in the Default.aspx page where you want to   apply Theme
    <%@ Page Language="C#" AutoEventWireup="true"CodeFile="Default.aspx.cs" Inherits="_Default" Theme="Theme1" %>
     

    The style properties of the skin file will not be visible at design time but only run time. Press F5 and see the output.

    Applying Themes on Controls at Run Time :


    You can apply theme at control level by setting its EnableTheming property to True and set the reference Theme file in Page directive. You can also create multiple themes and give a choice to the user to apply any theme at runtime.


    Steps :

    1. Add two Theme folders in the App_Themes folder (like Theme1 and Theme2)
    2. Now add sking file to each Theme folder (like Simple.skin and Inverse.skin)

    Simple.skin

     

    <asp:Label runat="server" width="300px" height="25px" font-bold="true"font-size="large"
    forecolor="green" backcolor="yellow" />
    <asp:TextBox runat="server" forecolor="Blue" backcolor="silver" font-bold="true"
    font-size="Medium" font-italic="True"/>
    <asp:Button runat="server" forecolor="green" backcolor="yellow" />
    Inverse.skin
    
    <asp:Label runat="server" width="300px" height="25px" font-bold="true"font-size="large"
    forecolor="yellow" backcolor="green" />
    <asp:TextBox runat="server" forecolor="silver" backcolor="blue" font-bold="true"
    font-size="Medium" font-italic="True"/>
    <asp:Button runat="server" forecolor="yellow" backcolor="green" />


     

    1. Create a Default.aspx page as shown
          

     The links are created using the below code

     <a href="Default.aspx?Theme=Theme1">Simple</a> | <ahref="Default.aspx?Theme=Theme2">Inverse</a><br />
    1. Add this in Default.aspx.cs   

    protected void Page_PreInit (object sender, EventArgs e)
    {
        Page.Theme = Server.HtmlEncode(Request.QueryString["Theme"]);
    }


     Press F5 and see the output by clicking both links


    Featured Articles


    Best Practices No 5: - Detecting .NET application memory leaks
    Memory leaks in .NET application have always being programmer's nightmare. Memory leaks are biggest problems when it comes to production servers. Productions servers normally need to run with least down time. Memory leaks grow slowly and after sometime they bring down the server by consuming huge chunks of memory. Maximum time people reboot the system, make it work temporarily and send a sorry note to the customer for the downtime. ... Read More
    .NET Best Practice No: 1:- Detecting High Memory consuming functions in .NET code
    One of the important factors for performance degradation in .NET code is memory consumption. Many developers just concentrate on execution time to determine performance bottle necks in a .NET application. Only measuring execution time does not clearly give idea of where the performance issue resides. Ok, said and done one of the biggest task is to understand which function, assembly or class has consumed how much memory. In this tutorial we will see how we can find which functions consume how much memory. This article discusses the best practices involved using CLR profiler for studying memory allocation.... Read More
    How to improve your LINQ query performance by 5 X times ?
    LINQ has been criticized by many early adopters for its performance issues. Well if you are just going to drag and drop using DBML code generator I am sure you will land up in to mess. Try doing this make a simple LINQ to SQL project using DBML and see your SQL profiler, I am sure you will never like to touch DBML code generator again. ... Read More
    Responses

    No response found. Be the first to respond this post

    Post Comment
    You must Sign In To post reply
    Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

    Hall of Fame    Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend