Take the 2-minute tour ×

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; }


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

share|improve this question
Do you want to make the swap on the server, or on the client side? –  RickNZ Dec 2 '11 at 12:05
add comment

3 Answers

up vote 2 down vote accepted

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)
share|improve this answer
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. –  DeeMac Dec 2 '11 at 11:58
add comment

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.

share|improve this answer
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? –  DeeMac Dec 2 '11 at 12:04
add comment

If you wan't thats to be done in client side, easy way is to use JQurey or Javascript as Jan describes above.

If you wan't it to do in server side, you can assign a id value to the element that you need to change styles and do something like this

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


yourID.Attributes.Add("style", "color: yourcolor;");
share|improve this answer
add comment

Your Answer


