Search code examples
asp.netcssparameter-passingusing-directives

Dynamically loading style sheets based on Server Controls


I have a website that will need to load basic style components based on the model (determined on backend SQL server based on user input)

The concept is that this website can contained parameterized look-and-feel components which are predefined based on a landing page.

Can any one provide a basic idea or example of how to accomplish this? One idea was to store style parameters at the database, but how could a style sheet pull this. Another idea is to have these predefined style sheets corresponding to the landpage, but this would require a server control, and we wouldn't be able to implement this in the to link the style sheet.


Solution

  • Style sheets cannot pull from a database, but you certainly can make a handler that serves up the CSS file rather than point to a physical CSS file.

    The bigger problem here, however, is more of a business problem. You have to figure out the mapping of controls or layouts to CSS files prior to coding this. If you don't I can almost guarantee you are going to experience some pain down the road when you system cannot handle the requirements. Do the design work up front if you don't want too much pain.

    Now, back to the issue. "Based on a landing page"? Do you mean different users hit different landing pages. If so, the styling can be applied to templates (easy in ASP.NET) or you can create a custom profile provider to marry style to user. I would think through those options. The storage of the file as a file or in the database is a separate issue.