user3300006
user3300006

Reputation: 13

Modifying ASP.NET stylesheet.css using code-behind

I'm new to ASP so a complete noob with C#, however I am strong in css/html and know some Javascript.

I have an ASP.NET web-app using an external "style.css" - please note that I hate using inline styles.

I want to modify the colour of an element based on user credentials from the server.

(In style.css): .userColour {background-color: #3c3c3c;}

So when the user logs in: (In C# of page):

Getting the user colour from the server probably has too many methods to warrant an answer here - I just need to be shown some basic method of addressing the style.css and iterating through it overwriting the colour value and saving it on completion.

Please note: I don't want to add or modify css classes server-side, or add inline styles, etc. I want to have the flexibility to assign ANY colour value at a later stage and for the app this is the most appropriate solution.

Thanks.

Upvotes: 0

Views: 1643

Answers (1)

recursive
recursive

Reputation: 86174

You can create a stylesheet that has a codebehind just like an aspx file. Here is a tutorial. http://cfouquet.blogspot.com/2006/06/making-dynamic-css-content-with-aspnet.html

Basically, your css template looks like this:

<%@ Page Language="C#" %> 
h1 { background-color:<%= ColorManager.Color %>; }

Upvotes: 2

Related Questions