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


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Changing theme dyanmically in asp.net

Posted By:Dhivakaran       Posted Date: October 31, 2010    Points: 50    Category: ADO.NET    URL: http://www.dotnetspark.com  

For changing theme dynamically we have to add two class files as below
 

First add the themes in app_theme folder with different names

 then create class like below. it is used to collect themes under the app_theme folder

public class ThemeManager

{

    #region Theme-Related Method

    public static List GetThemes()

    {

        DirectoryInfo dInfo = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("App_Themes"));

        DirectoryInfo[] dArrInfo = dInfo.GetDirectories();

        List list = new List();

        foreach (DirectoryInfo sDirectory in dArrInfo)

        {

            Theme temp = new Theme(sDirectory.Name);

            list.Add(temp);

        }

        return list;

    }

    #endregion

}


then add the below codes in a class file which should inherit the class System.Web.UI.Page


public class BasePage : System.Web.UI.Page

{

    protected override void OnPreInit(EventArgs e)

    {

        base.OnPreInit(e);

        if (Session["MyTheme"] == null)

        {

            Session.Add("MyTheme", "White");

            Page.Theme = ((string)Session["MyTheme"]);

        }

        else

        {

            Page.Theme = ((string)Session["MyTheme"]);

        }

    }

}

Then add the pages and it should inherit BasePage class then you can apply css classses in html pages 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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