Modify or Create a CSS class in C#

I have an aspx page with a ListView on it being populated from a database. A dropdown is at the top of the page and the user can select which client to view. Each client has different colors for text and borders and such. I have a stylesheet for every cleint, but in the css classes, I'm only changing 3 things and the rest stays the same.

 .grid
        {
            border: solid 2px #000; /** this changes **/
            font-family: Tahoma;
            font-size: 12px;
            width: 700px;
            background-color: #fff;
            margin: 0px auto;
            position: relative;
            margin-top: 50px;
            padding-bottom: 5px;
        }
        .grid H2
        {
            background: #8988a5 url(../images/sgtitle-bg.gif); /** this changes **/
            border-bottom: solid 1px #000;                              /** this changes **/
            height: 28px;
            line-height: 28px;
            margin: 0px;
            padding: 0px 0px 0px 5px;
            color: #000;
            font-size: 15px;
        }

We have over 40 clients coming and it's ridiculous to have over 40 style sheets when only 3 lines are changing.  How do I modify or create css classes in C#? This is .NET 4.0
troycompAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TeggertCommented:
Probably the best thing to do is create an aspx page with or without a codebehind file, then just do your css manipulation there. Here's a basic example.

<%@ Page Language="C#" %>
<%
    string color = "blue";
%>
H1 { background-color:<%= color %>; }


Then reference that file in your other pages just like you would any other css file.

<link type='text/css' rel='stylesheet' href='../myCSS.aspx' />
0
CCSOFlagCommented:
As an example:
<element name>.Style["width"] = "1000px";
0
troycompAuthor Commented:
@Teggert

I Like your suggestion, but I cant get my page to recognize the css in an aspx page

<link type='text/css' rel='stylesheet' href='../myCSS.aspx' />

I added this to my page, but no styling appears.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

troycompAuthor Commented:
My myCSS.aspx looks like this:

<%@ Page Language="C#"%>


<%@ Page Language="C#" %>
<%
   string color = "#123456";
%>


      /* Remove margins from the 'html' and 'body' tags, and ensure the page takes up full screen height */
html, body {height:100%; margin:0; padding:0;}
/* Set the position and dimensions of the background image. */
#page-background {position:fixed; top:0; left:0; width:100%; height:100%;}
/* Specify the position and layering for the content that needs to appear in front of the background image. Must have a higher z-index value than the background image. Also add some padding to compensate for removing the margin from the 'html' and 'body' tags. */
#content {position:relative; z-index:1;padding:10px;}
       
        .grid
        {
            border: solid 2px <%= color %>;
            font-family: Tahoma;
            font-size: 12px;
            width: 700px;
            background-color: #fff;
            margin: 0px auto;
            position: relative;
            margin-top: 50px;
            padding-bottom: 5px;
        }
        .grid H2
        {
            background: #8988a5 url(../images/sgtitle-bg.gif);
            border-bottom: solid 1px #000;
            height: 28px;
            line-height: 28px;
            margin: 0px;
            padding: 0px 0px 0px 5px;
            color: #000;
            font-size: 15px;
        }
0
TeggertCommented:
Just make sure the location of your myCSS.aspx file is correctly referenced. If it's in your site root, just do '/myCSS.aspx' or 'myCSS.aspx' instead of '../myCSS.aspx'
0
troycompAuthor Commented:
Its at the root. Im adding it dynamically, like i was doing for the other stylesheets:

           var link = new HtmlLink();
            link.Attributes.Add("href", Page.ResolveClientUrl("myCSS.aspx"));
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            head.Controls.Add(link);

0
TeggertCommented:
Give this a try.

            var link = new HtmlLink();
            link.Attributes.Add("href", Page.ResolveClientUrl("~/myCSS.aspx"));
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            Header.Controls.Add(link);
0
troycompAuthor Commented:
I tried that first, no luck. I even put the link directly on the page. No styling. My old cole looked like this:

link.Attributes.Add("href", Page.ResolveClientUrl("~/Styles/" + site + "Style.css"));

where the variable site was the client the user selected. This worked fine. I moved myCSS.aspx under the styles folder and updated my code

link.Attributes.Add("href", Page.ResolveClientUrl("~/Styles/CSS.aspx"));

No styling :(
0
troycompAuthor Commented:
Yes its CSS.aspx not nyCSS.aspx. I just called it myCSS.aspx to be consistent with what you called it
0
TeggertCommented:
Roger that. The only thing I see odd is that your CSS code example had two page directives. I assume that was just a paste typo?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
troycompAuthor Commented:
That fixed it!!!! Man you're a genius. I had no idea you could use an aspx page as a stylesheet. Thank you so much! 500 points for you
0
troycompAuthor Commented:
Wonderful
0
TeggertCommented:
No problem man. Glad it worked out. Feel free to post any other problems you run into here and I'll help out as I have time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.