1

I have the following inside a content place holder in my asp .net pages:

<style type="text/css">

    #sortable1 { list-style-type: none; margin: 0; padding: 0; zoom: 1; }
    #sortable1 li { margin: 3px; padding: 3px; width: 90%; border: 1px solid #000000; background: #000000; color: #FFFFFF; }
    #sortable1 li.highlightWorkflow { background: #FFFF00; color: #000000; }

</style>

I would ideally like to swap the #00000's for values held on the page, maybe in hidden fields. Is this possible?

1
  • Do you want to make the swap on the server, or on the client side? Commented Dec 2, 2011 at 12:05

3 Answers 3

2

You cannot modify your CSS file directly from asp.net, but you can do this with some creative use with a javascript library, like jQuery.

In theory you would use the following pseudocode

var colorCode = getColorCodeFromHiddenField();
$(field).prop(property, colorCode)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Jan! Looks like this could be solution. I've never touched JQuery so I'm gonna have to look further into this.
1

If your taget is to be able to modify the colors as you design, I suggest you take a look att Less Css (http://lesscss.org/). This lets you store a color code in a variable so you only have to change the value once.

If you however, need a way for users to change values, something like @Jan's suggestion is better.

1 Comment

Less looks brilliant David, thanks for that. Do you know if it's possible to reference the likes of hidden fields from inside Less code?
0

If you want that to be done on the client side, the easy way is to use JQuery or JavaScript as Jan describes above.

If you want to do it on the server side, you can assign an id value to the element that you need to change styles and do something like this:

yourID.Style.Add("color", something);

or

yourID.Attributes.Add("style", "color: yourcolor;");

Comments

Your Answer

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