Skip to content

How to create css file dynamic from code behind in asp net

Shivendra Singh

Asked Oct 26, 2015, 4:36 AM EDT2 answers
Share
LinkedInX
hi Friends,
I want to create dynamic CSS for multiple ASP.NET controls , I have created required css but not able to create the css file where I want to store this css.
For eaxample:
I want to host multiple site with different css /template but same code. so I want to design separate css file based on site Id. so the need is that when a user set their css for all controls then we will save it in a separate css file.

Please tell me the way how can i do this.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Vaibhav Agarwal
    0
    The best way of dynamic design(CSS) according the client is. Save 5 colors in a database field.
    And fix the order of these colors.
    1. BackGround.
    2. Fore Color
    3. Buttons Color
    4. Menus Color
    5. Body Color etc.
    Database table
    Client ID Theme
    100001 |#ABCDEF|#ABCDEF|#ABCDEF|#ABCDEF|#ABCDEF|
     
    .aspx Page
    After that create a
    .aspx.cs page
    DataTable dt = // Fetch the value from database.
    string[] arrColors=dt.rows[0]["THEME"].ToString().split("|");
    StringBuilder sbrDynamicCSS=new StringBuilder("");
    sbrDynamicCSS.Append("body{color :"+arrColors[0]+"}"); // Append CSS
    Add this String into div
    dynamicCSS.InnerHtml=sbrDynamicCSS.ToString();
     
     Actually main problem with Dynamic css is that. You can create and do everything but you can not load it dynamically created css. and It will be headache according the service point of view. suppose you have 10000 clients and 10000 file of css and you get a problem with any syntax of css tag then you change it 10000 files. Thats why try to change only theme colors.
    0
  • 0
    hi Vaibhav, Thanks for your effort. I have done this but I want to create a separate css file for all client.and don't interact with database for css.
    0