css file using passed variables from asp page to control background, text, tables, etc.

Here is my problem.  I have a asp page (1st Page) that passes values to another page (2nd page).  Some of these values passed need to control the css like background color, table border color, text color, etc.  The user is entering the color number minus the pound sign for each field passed.  I know these pass to the 2nd page correct becuase I can display them on the page using <%= Request.QueryString("myfieldname") %>.

My problem is programmatically control the css.  It appears I cannot use variables in a css file which is what I was trying to accomplish below?  

I have found a few examples of making the css file an asp page but I don't know how to write asp style sheets for the thinks i need to control.  If I have to use an asp style sheet I need examples or web sites to learn how to do css for text, tables, table borders, etc in asp.


1st Page: users enters some fields, clicks on a preview button, which takes then to page 2 and passed variables.


2nd Page: shows passed fields on page, but some passed fields need to control the css.

<link href="../CSS_Files/ERL_CSS_Templates.css?css_clrbackground=<%= Request.QueryString("myvarpassedfrom1stpage") %>" rel="stylesheet" type="text/css" />


CSS FILE: called from 2nd Page.

var m_pound = "#" ;
var m_color = new String("<%= Request.QueryString("css_clrbackground") %>") ;
var m_use = m_pound + m_color ;

BODY{
      background-color: {somehow use my the variable m_use here};
}

LVL 2
Torrey BatesPreidentAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
1. create the css with asp:
<link href="../asp/ERL_CSS_Templates.asp?css_clrbackground=<%= Request.QueryString("myvarpassedfrom1stpage") %>" rel="stylesheet" type="text/css" />

just have the asp set the content-type to text/css

OR

2. add the changes to the asp:

<link href="../CSS/ERL_CSS_Templates.css" rel="stylesheet" type="text/css" />
<style>
.css_clrbackground { <%= Request.QueryString("myvarpassedfrom1stpage") %> }
</style>


Michel
PS: http://www.w3schools.com/css/default.asp
0
 
aescntConnect With a Mentor Commented:
<link href="../CSS_Files/ERL_CSS_Templates.css?css_clrbackground=<%= Request.QueryString("myvarpassedfrom1stpage") %>" rel="stylesheet" type="text/css" />

You can't really do this -- unless your css file is renamed to an asp page, i.e., ERL_CSS_Templates.asp. If you're going this route, you will need in the beginning
   <% Response.ContentType = "text/css" %>
...and somehow bypass cache'ing issues (since you'll need to get the CSS file every time, instead of keep a copy in the cache), which I think you're better off not doing (you can't really guarantee that the browser will or will not refresh the CSS file).

Your best bet, IMHO, is to put inline styles, as mplungjan has answered. Just to clarify his code:

   <link href="../CSS/ERL_CSS_Templates.css" rel="stylesheet" type="text/css" />
   <style type="text/css">
    body { background-color: <%= Request.QueryString("css_clrbackground") %>; }
   </style>

(Btw, the code above has an XSS vulnerability. Try to spot it [and fix it].)
What this does is put inline styles in the HTML page, which will override anything on the linked stylesheets. For instance, ERL_CSS_Templates.css defines body background color as "#333333", but if the inline style defines it as "#aa8833", it will override the previous value.
0
 
Michel PlungjanIT ExpertCommented:
yeah, sorry I somehow missed the last part where the css was shown...
0
 
Torrey BatesPreidentAuthor Commented:
I split the points because Michel got me started and aescnt explanation sealed the deal.

Thanks for the fast responses, big help.

Regards,
Torrey
0
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.

All Courses

From novice to tech pro — start learning today.