Click here to Skip to main content
16,017,954 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
user want to change theme by clicking on a given options Like greentheme,redtheme etc. how can i implement this?
Posted

This is very easily googled. If you google "change themes at runtime" the first result is on this very site: How to change page theme in asp.net 2.0 dynamically at runtime[^] and it answers your question.
Please google your question first.
 
Share this answer
 
C#


I find this link vey useful :
http://www.codeproject.com/Articles/18300/How-to-change-page-theme-in-asp-net-2-0-dynamicall

I added themes : As White , Yellow and Red In my Project .

To add theme :

C#
<asp:button runat="server" xmlns:asp="#unknown">
  BackColor="White" 
  ForeColor="Black" 
  Font-Name="Times New Roman" 
  Font-Size="12px" />


<asp:button runat="server">
  BackColor="Red" 
  ForeColor="Green" 
  Font-Name="Arial Black" 
  Font-Size="12px" />

<asp:button runat="server">
  BackColor="Yellow" 
  ForeColor="Orange" 
  Font-Name="Comic Sans MS" 
  Font-Size="12px" />



</asp:button></asp:button></asp:button>


I have taken two buttons for Yellow and Red Theme and a label to Display message . Code is as below

<pre lang="HTML">
<asp:button id="btnYellowTheme" runat="server" text="Yellow Theme" style="position :absolute ; left: 76px; top: 74px;" onclick="btnYellowTheme_Click" xmlns:asp="#unknown" />       
<asp:button id="btnRedTheme" runat="server" text="Red Theme" style="position :absolute ; left: 225px; top: 74px;" height="24px" onclick="btnRedTheme_Click" xmlns:asp="#unknown" />       
<asp:label id="lblDisplay" runat="server" text="" style="position :absolute; left: 135px; top: 34px;" xmlns:asp="#unknown"></asp:label>


For Coding Part , to apply theme dynamically :


C#
public partial class _Default : System.Web.UI.Page 
{

    string thmName; 
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Page_PreInit(Object sender, EventArgs e)
    {
        thmName = (string)Session["ThemeName"];
        if (thmName != null)
        {
            Page.Theme = thmName;
            lblDisplay.Text = "You have applied Theme :" + (string)Session ["ThemeName"];
        }
        else
        {
            thmName = "White";
            Page.Theme = thmName;
            lblDisplay.Text = "This is default White Theme";
        }
    }
    protected void btnYellowTheme_Click(object sender, EventArgs e)
    {
        thmName = "Yellow";
        Session["ThemeName"] = thmName;
        Session["ThemeName"] = "Yellow";
        Server.Transfer(Request.FilePath);  
    }
    protected void btnRedTheme_Click(object sender, EventArgs e)
    {
        thmName = "Red";
        Session["ThemeName"] = thmName;
        Response.Redirect("Default.aspx");
        Session["ThemeName"] = "Red";
        Server.Transfer(Request.FilePath);
    }
}





<pre lang="text">
 
Thank You 
 
Share this answer
 
 
Share this answer
 
Hi,

Please check the following link.

Style Sheet Switcher[^]

Thanks,
Imdadhusen
 
Share this answer
 
Here is a Great Step by Step Tutorial on Skins and Themes in ASP.NET

http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx[^]
 
Share this answer
 
In a handler for the page's PreInit method, set the page's Theme property. such as:
C#
protected void Page_PreInit(object sender, EventArgs e)
{   
            Page.Theme = "BlueTheme";            
    
}
or as per your requirement try as :

In the designer source add a dropdown as :
XML
<asp:DropDownList ID="Themes" runat="server" AutoPostBack="True">
        <asp:ListItem Selected="True">Default</asp:ListItem>
            <asp:ListItem>SmokeAndGlass</asp:ListItem>
            <asp:ListItem>UglyRed</asp:ListItem>
        <asp:ListItem>SkyHigh</asp:ListItem>
        <asp:ListItem>BasicBlue</asp:ListItem>
        </asp:DropDownList>


In a handler for the page's PreInit method, set the Theme .

C#
protected void Page_PreInit(object sender, EventArgs e)
    
    {
        string theme = "";
        if (Page.Request.Form.Count > 0)
        {
            theme = Page.Request["Themes"].ToString();
            if (theme == "Default")
            {
                theme = "";
            }
        }
        this.Theme = theme;
    }     
    
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900