Monday, October 24, 2011

ASP.NET THEMES

Hi Folks,,

  today i am going to write about  an old feature of asp.net , but thought this may help you.  
Long story short, i think every body knows what theming is . so let's start to look how to implement it .

First of all there is a special folder type for themes  in ASP.net , which is called APP_THEMES. 
Before you start with you need to add App_theme folder to your web site/application.

Go to your project right click on it and Select Add >>> Add ASP.NET Folder >> Theme

Bravo now you have the theme folder . Next what you have to do create folders for each of theme you want..

e.g. Let's say you want three themes according to user types , which will be Pre paid / Postpaid and For Unregistered Guests . what you will be doing is creating three folders  and name it accordingly.


Then for each folder you can add separate css file which will be used to dress your web pages.
e.g. with in the prepaid folder you can add prepaid.css  file. and especially you can add skin file also which will used to decorate your controls.

e.g. you want all the text-box of your web page to have black border when you select a specific theme. what you can do is you can add a skin file to , specific theme folder and give a name for it and then add some thing like this 

<asp:TextBox: runat="server" border ="Blah blach balcj,,....."/> .


Last the interesting part . How to change the themes ?

there are two options you can use web.config to set a them.  this is useful when you are developing a product and you want to give the product to separate customers with different looks,.
this is how to you can do it . in the web config  system.web section

 <pages theme="theme name"></pages> 

 Other option is to change the theme on the fly.which means dynamically changing the theme,

protected override void OnPreInit(EventArgs e) {
 Page.Theme = "ThemeName";

}

That's all ..

Thanks

 















No comments:

Post a Comment