0

i have a CSS Style in my .css class in which a color is set to Blue for hundret of Buttons.

My customer now wants a option for green buttons, saved by a database field, so I ask the field:

                 if (!String.IsNullOrEmpty(user.SetColorButtons) && user.SetColorButtons == "Grün")
            {
                 //Change Style
            }

Now how to change the css-file here?

Its very hard to not change the file becuase I have arount 300 buttons in this site in around 40 pages, would be the hell to change it in the code in every freaking code behind...

1
  • Not enough info! Do all buttons have the same class? Do you have button or input elements? Are you looking for a Javascript solution which works 'on-the-fly'? Commented Sep 17, 2013 at 14:55

3 Answers 3

2

Keep two versions of the css file like yourproduct-blue.css and yourproduct-green.css and when the page loads, check the db to determine which css file to be used. Then it is all about writing an if condition to load the corresponding css file.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the Literal object in your <head> tag:

<asp:Literal runat="server" id="Csslink"></asp:Literal>

Then in your code behind you can do something like:

if (!String.IsNullOrEmpty(user.SetColorButtons) && user.SetColorButtons == "Grün"){
    CssLink.Text = "<link rel=\"stylesheet\" type=\"text/css\" href=\"theme1.css\">";
}
else{
    CssLink.Text = "<link rel=\"stylesheet\" type=\"text/css\" href=\"theme2.css\">";
}

Comments

0

Here is one way:

protected void ButtonServer_Click1(object sender, EventArgs e)
{
    MyButton.Style[HtmlTextWriterStyle.BackgroundColor] = "red";
}

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.