2

I searched google and SO, but did not find a solution.

I have an asp.net web app that allows users to customize some GUI aspects (such as font color, add a custom logo etc). This information is stored in the user profile database.

I have a css file that populates font colors etc. The main page, loads the users profile from the database, and customizes the page accordingly.

Aside from having each label with its own "font-color=", how can I display the CSS elements, based on the user profile information returned from the database? Thx

1

3 Answers 3

4

You can include an extra CSS file that points to an ASPX page:

<link rel="stylesheet" type="text/css" href="/CustomStyles.aspx" />

Then in CustomStyles.aspx change the default content-type:

Response.Clear()
Response.ContentType = "text/css"

Then just start outputting your styles:

Response.Write("#awesome-button{color:" & ColorFromDatabase & ";}"

Make sure that this file is included after the other styles so that it takes precedence. You might want to also throw an !IMPORTANT in there, too.

Response.Write("#awesome-button{color:" & ColorFromDatabase & " !IMPORTANT;}"
Sign up to request clarification or add additional context in comments.

2 Comments

+1 Wow, I think we were a dead heat. I don't think I've ever seen "answered in 0 seconds" before! yfrog.com/j2ojtp
Do you know of an enum or official wrapper for this, to avoid hardcoded or invalid colors? Anything at all that makes sense to work with in an ASP.NET MVC project.
2

It depends on how you have the information stored, but you can add styling to elements through code like this:

Button1.Style["font-weight"] = "bold";

Or you can just apply a CSS class to the control:

Button1.CssClass = "buttonStyle";

Comments

2

You could have a page that just returns a CSS file based on the preferences stored in the database. So you would have:

<link rel="stylesheet" href="somepage.aspx?userid=<%=userID%>">

You could probably even do that easily enough with a classic ASP page, a web service, etc.

The point is that that page would generate the same basic stylesheet, filling in the right colors etc. that the user has chosen. This way you don't have to perform a bunch of style changes in server-side or client-side code after the page has loaded, or mix your user preference code in with your HTML, or change much about the base pages if you want to change the way the stylesheet works. It also makes it easy to test your stylesheet outside of testing the site itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.