Solved

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

Posted on 2006-11-19
4
249 Views
Last Modified: 2008-02-01
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};
}

0
Comment
Question by:Torrey Bates
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 17977522
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
 
LVL 6

Assisted Solution

by:aescnt
aescnt earned 125 total points
ID: 17977787
<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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17978574
yeah, sorry I somehow missed the last part where the css was shown...
0
 
LVL 2

Author Comment

by:Torrey Bates
ID: 17985459
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question