Theme changing on the fly using ASP.Net 2.0

Hi

Now the users can change the look and feel of the site as per their choice in my site. You can change the radio button on the left and accordingly the full theme (images, skin, and css) will change. This can be done very easily in asp.net 2.0.

After my friend (Thanks to Farghana) created a new theme for the site it required less than 10 line of code to change the theme on the fly.

Here is how I did it. All my pages are inheriting from basewebpage which inherits from System.Web.UI.Page. In basewebPage I overrode the StyleSheetTheme method like this.
public override string StyleSheetTheme
    {
        get
        { return HttpContext.Current.Profile["StylesheetTheme"].ToString();}
        set
        { HttpContext.Current.Profile["StylesheetTheme"] = value; }
    }

Here I am changing the stylesheet theme to use profiles StylesheetTheme. Next I went to the master page and added 2 radio buttons. On the check changed event of the radio button I set the profile to appropriate theme and redirected the page to itself.

      Profile.StylesheetTheme = "Ultra";
   Response.Redirect(Request.FilePath, true);

Also on the page load I am checking for the current theme and making the correct Radio button checked.

Also in the web.config file I added the following tag
    <profile>
      <properties>
        <add name="StylesheetTheme" defaultValue="Blue"  allowAnonymous="true"  />
      </properties>
    </profile>

Here I am adding a propert with name stylesheetTheme and giving the default tehme as Blue. Also I want the Ananymous user to be able to switch from one theme to another hence allowAnonymous="true". Also for this to work I have to add the following tag to the config.

    <anonymousIdentification enabled="true" />

Hope this helps
Thanks
Vikram

Share this post   Email it

Feedback

Posted on 7/27/2007 12:00:20 PM

Sorry for saying this.
But this article is worthless, its first of all hard to figure out the "middle steps" the idea with the radio button is just not intelligent, a drop down list with many themes would be much more practical.
and at last it just dont work on the hole site.

Posted on 2/10/2008 8:37:41 AM

dear
where you written this class please provide me complete detail of code

public override string StyleSheetTheme
{
get
{ return HttpContext.Current.Profile["StylesheetTheme"].ToString();}
set
{ HttpContext.Current.Profile["StylesheetTheme"] = value; }
}

Thanks in advance.

Posted on 2/10/2008 8:54:46 AM

Hi shamshuddin,

The code is written in the BaseWebPage of all my classes.

Here is what the BaseWebPage class looks like

public class BaseWebPage:System.Web.UI.Page
{
public override string StyleSheetTheme
{
get
{
return HttpContext.Current.Profile["StylesheetTheme"].ToString();
}
set
{
HttpContext.Current.Profile["StylesheetTheme"] = value;
}
}
}

Posted on 3/16/2009 6:43:13 AM

Hai whilie running locally it is working fine, but while i am configure it in IIS it is giving the following error. Please help anybody regarding this.

"
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
"

and also the following error

Source Error:

Line 27: get
Line 28: {
Line 29: return HttpContext.Current.Profile["StylesheetTheme"].ToString();
Line 30: }
Line 31: set

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2010 Vikram Lakhotia