Search - Articles - Dev Forums - Favorites - Member Login
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009


Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Build the right apps the right way with powerful development tools.
Visual Studio 2010. Learn more...
Working with Themes and Skin files in ASP.NET 2.0

Author: Aadil
Download Source Code : 212_Default.zip

This article will get you started using Themes, a new feature introduced in ASP.NET 2.0

When you started working with ASP.NET 2.0, especially using Visual Studio 2005 and added controls to the web page like a Textbox control you may of have recognized that there are two new properties (attributes) present in almost every control. They are the EnableTheming and ThemeID. Also there are additional attributes for the Page directive related to Themes.

 

Themes are a feature similar to style sheets as they help to supply a standard look and feel to web controls. You can use CSS style sheets to supply styles to HTML elements but if you wanted to use a set of predefined styling attributes to your web controls then you should use a Theme.

 

Themes are contained in a  special ASP.NET folder called App_Themes and each Theme you want to add in your web application should reside in a separate folder under this App_Themes folder. Let’s say you want to create a Theme called Dallas for the visitors that are coming from Dallas then you can create a DallasTheme folder under App_Themes folder to represent this Theme. In this folder you need to create a skin file. A skin file a file in which you describe the visual styles that are used by pages that will use this Theme. The name if the skin file is not important but the extension should be .skin.

 

In the skin file you just need to add the exact definitions of the web controls with all the visual attributes you want. You need to add the runat=”server” attribute but beware of adding the ID attribute because that will cause an error. For example I have a skin file with the following contents

 

<asp:TextBox runat="server" Font-Names="Verdana" Font-Size="11px" Width="200px" BorderStyle="Solid" BorderColor="#cc6666" BackColor="#ffcccc" />

 

And this file is placed in the App_Themes/DallasTheme folder. Remember that the theme is identified by the theme folder name in this case DallasTheme.

 

After you’ve placed the skin file you need to set a web page to use this Theme. You can enable a Theme for the entire page by setting the Theme attribute of the page equal to the name of the Theme. In this case it would be

 

<%@ Page Language="VB" Theme="DallasTheme" %>

 

Now at every place where a Textbox web control is used, it will be rendered with the styles defined in the skin file. If you want to disable the Theme for a specific control you can set its EnableTheming property to false and it won’t get the styles from the skin file and instead you can add your own b specifying attributes.

 

You can also define more than one style for a web control in the skin file by adding the SkinID attribute to the web control definition in the skin file and in the web page that is utilizing the Theme you can set the control’s SkinID equal to the one you want to use from the skin file.

Article Comments
In my project i want to use the ASP 2.0 themes and skins feacture.

i want to change the Skinid dinamically at runtime based on the user. is it possible.. clarify me in this..

regards,
Raju

Posted on 7/10/2006 10:29:42 AM by Raju

hi....this is for Raju......


hi Raju....pls do go through the site....here u can get alot of idea.....

http://www.codeproject.com/aspnet/ThemesAndSkins.asp

Posted on 8/9/2006 9:50:26 AM by syed

your article is very nice and good. really its very useful to me thank you.

Posted on 1/7/2008 8:46:01 AM by SRINIVAS

Hi
i have a doubt about theme concept in asp.net 2.0 my Question is Can we Apply the CssClass for Skin file

Posted on 1/21/2008 4:28:21 AM by mohamed Siddik

asdfas

Posted on 6/7/2008 9:16:30 AM by asdfs

hi can any one give me solution? when my webpage started one of my text field color has changed. i dont know why

Posted on 8/18/2008 12:16:49 AM by Khalid

how can i create a skin file in c#.net?

Posted on 12/17/2008 6:06:55 AM by andrews

It was really amazing.But should be more descriptive.

Posted on 12/17/2008 8:23:52 AM by Pravin Patil

your article is very nice and good. really its very useful to me thank you.

Posted on 12/10/2009 6:42:18 AM by kumar

An unhandled exception has occured. There was an error parsing the theme. The ID property of the control[textbox] can not be applied through a control skin.

Please help me remove this exception. i am a novice programmer.

Posted on 2/10/2010 11:17:43 AM by Arsalan

Hi Arsalan, I think you have applied ID for your control that's why you have this problem. Just remove the ID from your skin file. Remember you can give SkinID for your control as per your need to distinguish the two same type of controls

Posted on 3/6/2010 12:48:01 AM by Chintak

Hi , How to add multiple themes in asp.net

Posted on 4/19/2010 6:37:41 AM by sujana

What is skin file?

Posted on 6/8/2010 12:45:14 PM by Ranjith

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Using Different Master Pages for Different Browsers in ASP.NET 2.0

Disclaimer - Privacy
© 2002-2010 DevASP.net