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

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to apply css class dynamically

Posted By: Amitesh Kaushik     Posted Date: October 10, 2010    Points:2   Category :ASP.Net
I have five css classes if I select any one of them and press "APPLY" button then it should be applied to the home page of my web site.

Author: Asha.MP             
Posted Date: October 12, 2010     Points: 5   


I code behind you can set the cssclass by using
Me.BtnStyle.CssClass = "CssStyle"

defined cssStyle should define in aspx page or in external css folder,
to link external folder, define like this in aspx page

<asp:Content ID="Content1" ContentPlaceHolderID="ConPhlHead" runat="server">
<link href="App_Themes/TAS/Applicant.css" rel="stylesheet" type="text/css" />

App_Themes/TAS/---> represents the path
Applicant.css-->this is the css file name.

You can use button click event, according the button click you can set that perticular css styles.

Thanks and Regards,
Author: Dhivakaran             
Posted Date: October 19, 2010     Points: 5   


You can for theme concept for dynamicaly change the CSS stlyes.

follow the belo steps

1)Create a App_theme folder in project
2)Add differnt theme inside app_theme folder.
3) within app_Code folder add the below classes
public class ThemeManager

public static List<Theme> GetThemes()
DirectoryInfo dInfo = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("App_Themes"));
DirectoryInfo[] dArrInfo = dInfo.GetDirectories();
List<Theme> list = new List<Theme>();
foreach (DirectoryInfo sDirectory in dArrInfo)
Theme temp = new Theme(sDirectory.Name);
return list;
public class Theme
private string _name;
public string Name
get { return _name; }
set { _name = value; }
public Theme(string name)
Name = name;
public class BasePage : System.Web.UI.Page
protected override void OnPreInit(EventArgs e)
if (Session["MyTheme"] == null)
Session.Add("MyTheme", "White");
Page.Theme = ((string)Session["MyTheme"]);
Page.Theme = ((string)Session["MyTheme"]);

4) then inherit teh class "BasePage" every aspx.cs file

Dhivakaran T

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

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