Avatar of SeTech
SeTech
Flag for United States of America

asked on 

Dynamically choose/change CSS at run-time

On one of our sites, we're hoping to implement a feature that I'm not sure how to implement. It's ASP.Net 2.0, using C#.

Inside the Master Page, there's an image not set to anything. Inside default.aspx, there's a GridView. Now, in the code-behind pages, the banner is set based on a QueryString variable called "Page" (if it exists, it tries to find an image file named the same thing as the Page querystring value. If it finds it, it sets it accordingly. If not, or if there is no QueryString value, it sets to a default image). In the default.aspx.cs Page_Load event, the QueryString variable Page is sent into a SQL stored procedure to get a DataSet to bind to the GridView.

Now, what we would like to add is the capability for multiple CSS files, also named according to the Page QueryString value. So basically, on Page_Load for the Master Page, I'd like to be able to set the CSS file it uses (of course using a default if one doesn't exist, like the image). But I can't find anything like this on the Internet so far. Is there some property of Page for whatever CSS file it links to? I mean far more than just individual elements' CssClass properties, I'm looking for a way to basically dynamically set the <link> tag in the header based on what the QueryString contains.
C#CSSASP.NET

Avatar of undefined
Last Comment
SeTech

8/22/2022 - Mon