473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I combine ASP with external CSS?

I am trying to display a random background image for a webpage. I found
this code to do it

<%
'Defines the number of background images you have
Const NUMBER_OF_IMAGE S = 2

'Initiates the randomize function
Randomize

'Sets a variable: this will be used to hold the
'random generated value
Dim intImageNumber

'This is where we create the random number
intImageNumber = Int((NUMBER_OF_ IMAGES * Rnd) + 1)
%>
Modify the body tag to accept the random number. In this case we are going
to place it within the image so as to facilitate the selection of a random
image.

<BODY BACKGROUND="bg_ <%= intImageNumber %>.gif">

This did work.

In my case, I have an external style sheet with this defined:

body {
color:#333;
background-color: gray;
background-image: url(../images/bg_<%=intImageN umber%>.JPG);
background-attachment: fixed;
margin:20px;
padding:0px;
font:11px verdana, arial, helvetica, sans-serif;
}

and it is included in my main page with

<head>
<style type="text/css" media="screen"> @import "css/cvs.asp";</style>
</head>

which comes after the above randomizing script

I removed <BODY BACKGROUND="bg_ <%= intImageNumber %>.gif"> from the main
page and replaced it with just <body> thinking that since it is defined in
the external CSS file I wouldn't need it on each page.

I just got a gray background. Since I am really new to ASP and CSS I am not
sure the variables are global throughout included files or not. I wanted to
have the background image defined in the style file since it is used
everywhere so rather than modiying <body> for each page I could have it in
one place.

Can this be done this way? Is there a better way to handle this situation?

Many thanks

Richard Speiss
Jul 19 '05 #1
14 2527
Richard Speiss wrote on 08 jun 2004 in
microsoft.publi c.inetserver.as p.general:
<head>
<style type="text/css" media="screen"> @import "css/cvs.asp";</style>
</head>


<link type="text/css" href="css/cvs.asp" rel="stylesheet ">

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #2
"Richard Speiss" wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
: I am trying to display a random background image for a webpage. I found
: this code to do it
:
: <%
: 'Defines the number of background images you have
: Const NUMBER_OF_IMAGE S = 2
:
: 'Initiates the randomize function
: Randomize
:
: 'Sets a variable: this will be used to hold the
: 'random generated value
: Dim intImageNumber
:
: 'This is where we create the random number
: intImageNumber = Int((NUMBER_OF_ IMAGES * Rnd) + 1)
: %>
:
:
: Modify the body tag to accept the random number. In this case we are going
: to place it within the image so as to facilitate the selection of a random
: image.
:
: <BODY BACKGROUND="bg_ <%= intImageNumber %>.gif">
:
: This did work.
:
: In my case, I have an external style sheet with this defined:
:
: body {
: color:#333;
: background-color: gray;
: background-image: url(../images/bg_<%=intImageN umber%>.JPG);
: background-attachment: fixed;
: margin:20px;
: padding:0px;
: font:11px verdana, arial, helvetica, sans-serif;
: }
:
: and it is included in my main page with
:
: <head>
: <style type="text/css" media="screen"> @import "css/cvs.asp";</style>
: </head>
:
: which comes after the above randomizing script
:
: I removed <BODY BACKGROUND="bg_ <%= intImageNumber %>.gif"> from the main
: page and replaced it with just <body> thinking that since it is defined in
: the external CSS file I wouldn't need it on each page.
:
: I just got a gray background. Since I am really new to ASP and CSS I am
not
: sure the variables are global throughout included files or not. I wanted
to
: have the background image defined in the style file since it is used
: everywhere so rather than modiying <body> for each page I could have it in
: one place.
:
: Can this be done this way? Is there a better way to handle this
situation?

Remove the background-image line from your external CSS and just use it in
an onload.

<body onload="bg_<%= intImageNumber %>.gif">

Perhaps if your CSS was linked in prior to the script running and it was
..css instead of .asp, then perhaps the ASP processor would process that part
before rendering the page to the client. As it is now, and you can test by
loading the cvs.asp by itself and looking at the source, you'll see what is
actually being returned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #3
Thanks but that didn't make a difference

Richard

"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ***********@194 .109.133.29...
Richard Speiss wrote on 08 jun 2004 in
microsoft.publi c.inetserver.as p.general:
<head>
<style type="text/css" media="screen"> @import "css/cvs.asp";</style>
</head>


<link type="text/css" href="css/cvs.asp" rel="stylesheet ">

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 19 '05 #4

But if I use <body onload ... , then I need to have that piece of code on
each .asp page which is what I was trying to avoid.

If I load cvs.asp by itself then it wouldn't have intImageNumber filled in
since the number is generated by the file that includes it. I guess that's
my question; whether a value generated in a page can be used by something
that is included. Your point is good though. Which is done first? Does
the ASP VB code get executed first or does the style inclusion in the <head>
section.

By doing a little test it looks like intImageNumber doesn't make it from
index.asp to cvs.asp. Or I am still missing something

Thanks

Richard
Remove the background-image line from your external CSS and just use it in
an onload.

<body onload="bg_<%= intImageNumber %>.gif">

Perhaps if your CSS was linked in prior to the script running and it was
.css instead of .asp, then perhaps the ASP processor would process that part before rendering the page to the client. As it is now, and you can test by loading the cvs.asp by itself and looking at the source, you'll see what is actually being returned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 19 '05 #5
index.asp and cvs.asp are separate asp scripts so the value of
intImageNumber will not pass from index to cvs. You will need to include the
random background code in the cvs.asp file.

The sequence of execution is:

index.asp is requested by the browser

index.asp is executed on the server and the generated html returned to the
browser. This html will include your style or link tag. Note that at this
time the cvs.asp script has not been called.

browser finds the link tag or style import directive in the html and sends a
request for cvs.asp

cvs.asp is executed on the server and the resulting text is returned (You
will probably have to set response.conten ttype to whatever is valid for a
stylesheet in order for the browser to use the styles).

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Richard Speiss" <rs*****@mtxinc .com> wrote in message
news:uv******** *****@TK2MSFTNG P11.phx.gbl...

But if I use <body onload ... , then I need to have that piece of code on
each .asp page which is what I was trying to avoid.

If I load cvs.asp by itself then it wouldn't have intImageNumber filled in
since the number is generated by the file that includes it. I guess that's
my question; whether a value generated in a page can be used by something
that is included. Your point is good though. Which is done first? Does
the ASP VB code get executed first or does the style inclusion in the <head> section.

By doing a little test it looks like intImageNumber doesn't make it from
index.asp to cvs.asp. Or I am still missing something

Thanks

Richard
Remove the background-image line from your external CSS and just use it in an onload.

<body onload="bg_<%= intImageNumber %>.gif">

Perhaps if your CSS was linked in prior to the script running and it was
.css instead of .asp, then perhaps the ASP processor would process that

part
before rendering the page to the client. As it is now, and you can test

by
loading the cvs.asp by itself and looking at the source, you'll see what

is
actually being returned.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -

http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Jul 19 '05 #6
You can map css pages to be processed through the same engine as the ASP
pages. Then you can just embed your ASP code in the CSS file.

"Richard Speiss" <rs*****@mtxinc .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I am trying to display a random background image for a webpage. I found
this code to do it

<%
'Defines the number of background images you have
Const NUMBER_OF_IMAGE S = 2

'Initiates the randomize function
Randomize

'Sets a variable: this will be used to hold the
'random generated value
Dim intImageNumber

'This is where we create the random number
intImageNumber = Int((NUMBER_OF_ IMAGES * Rnd) + 1)
%>
Modify the body tag to accept the random number. In this case we are going
to place it within the image so as to facilitate the selection of a random
image.

<BODY BACKGROUND="bg_ <%= intImageNumber %>.gif">

This did work.

In my case, I have an external style sheet with this defined:

body {
color:#333;
background-color: gray;
background-image: url(../images/bg_<%=intImageN umber%>.JPG);
background-attachment: fixed;
margin:20px;
padding:0px;
font:11px verdana, arial, helvetica, sans-serif;
}

and it is included in my main page with

<head>
<style type="text/css" media="screen"> @import "css/cvs.asp";</style>
</head>

which comes after the above randomizing script

I removed <BODY BACKGROUND="bg_ <%= intImageNumber %>.gif"> from the main
page and replaced it with just <body> thinking that since it is defined in
the external CSS file I wouldn't need it on each page.

I just got a gray background. Since I am really new to ASP and CSS I am not
sure the variables are global throughout included files or not. I wanted to
have the background image defined in the style file since it is used
everywhere so rather than modiying <body> for each page I could have it in
one place.

Can this be done this way? Is there a better way to handle this situation?

Many thanks

Richard Speiss

Jul 19 '05 #7
Oh that was way too easy. I wasn't thinking that I could actually execute
the VB script inside a style file since it was just declarations but when I
think about it, it does make sense.

Thanks a lot. It's working great now

RIchard

"Lance Wynn" <la********@N.O .S.P.A.M.hotmai l.com> wrote in message
news:u8******** ******@TK2MSFTN GP10.phx.gbl...
You can map css pages to be processed through the same engine as the ASP
pages. Then you can just embed your ASP code in the CSS file.

"Richard Speiss" <rs*****@mtxinc .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I am trying to display a random background image for a webpage. I found
this code to do it

<%
'Defines the number of background images you have
Const NUMBER_OF_IMAGE S = 2

'Initiates the randomize function
Randomize

'Sets a variable: this will be used to hold the
'random generated value
Dim intImageNumber

'This is where we create the random number
intImageNumber = Int((NUMBER_OF_ IMAGES * Rnd) + 1)
%>
Modify the body tag to accept the random number. In this case we are going
to place it within the image so as to facilitate the selection of a random
image.

<BODY BACKGROUND="bg_ <%= intImageNumber %>.gif">

This did work.

In my case, I have an external style sheet with this defined:

body {
color:#333;
background-color: gray;
background-image: url(../images/bg_<%=intImageN umber%>.JPG);
background-attachment: fixed;
margin:20px;
padding:0px;
font:11px verdana, arial, helvetica, sans-serif;
}

and it is included in my main page with

<head>
<style type="text/css" media="screen"> @import "css/cvs.asp";</style>
</head>

which comes after the above randomizing script

I removed <BODY BACKGROUND="bg_ <%= intImageNumber %>.gif"> from the main
page and replaced it with just <body> thinking that since it is defined in
the external CSS file I wouldn't need it on each page.

I just got a gray background. Since I am really new to ASP and CSS I am not sure the variables are global throughout included files or not. I wanted to have the background image defined in the style file since it is used
everywhere so rather than modiying <body> for each page I could have it in
one place.

Can this be done this way? Is there a better way to handle this situation?
Many thanks

Richard Speiss

Jul 19 '05 #8
No, you can't do that, because the CSS file is not included in the
server-side script, it is only sent to the client-side browser for parsing.

You can use a CSS file as ASP:

body {
....
background-image: url(../images/bg_<%=Request.Q ueryString("i") %>.jpg);
....
}

Then call it like this:

<link rel=stylesheet href=css.asp?i= <%=intImageNumb er%>>

Or, you can just put the style inline instead of a linked file.

You lose the benefit of using an external style sheet by making the content
dynamic, but you can keep the same maintenance benefit by using an external
ASP file.

--
http://www.aspfaq.com/
(Reverse address to reply.)

"Richard Speiss" <rs*****@mtxinc .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I am trying to display a random background image for a webpage. I found
this code to do it

<%
'Defines the number of background images you have
Const NUMBER_OF_IMAGE S = 2

'Initiates the randomize function
Randomize

'Sets a variable: this will be used to hold the
'random generated value
Dim intImageNumber

'This is where we create the random number
intImageNumber = Int((NUMBER_OF_ IMAGES * Rnd) + 1)
%>
Modify the body tag to accept the random number. In this case we are going
to place it within the image so as to facilitate the selection of a random
image.

<BODY BACKGROUND="bg_ <%= intImageNumber %>.gif">

This did work.

In my case, I have an external style sheet with this defined:

body {
color:#333;
background-color: gray;
background-image: url(../images/bg_<%=intImageN umber%>.JPG);
background-attachment: fixed;
margin:20px;
padding:0px;
font:11px verdana, arial, helvetica, sans-serif;
}

and it is included in my main page with

<head>
<style type="text/css" media="screen"> @import "css/cvs.asp";</style>
</head>

which comes after the above randomizing script

I removed <BODY BACKGROUND="bg_ <%= intImageNumber %>.gif"> from the main
page and replaced it with just <body> thinking that since it is defined in
the external CSS file I wouldn't need it on each page.

I just got a gray background. Since I am really new to ASP and CSS I am
not
sure the variables are global throughout included files or not. I wanted
to
have the background image defined in the style file since it is used
everywhere so rather than modiying <body> for each page I could have it in
one place.

Can this be done this way? Is there a better way to handle this
situation?

Many thanks

Richard Speiss

Jul 19 '05 #9
> Oh that was way too easy.

Yes, and you know what they say when a solution is very easy: it probably
isn't the best solution. If you're using a version of IIS prior to 6.0,
this "easy" solution is going to cost you dearly, because every single CSS
file your site serves will be parsed by the ASP engine (and again, there go
the benefits of re-using a linked CSS file).

A
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2700
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent, however we will have brokers and customers that also need to connect and will require a username and password. In this case we were going to store their...
3
11516
by: Stephen Matthews | last post by:
Help please i have a file which im importing, however it is a single column, the data looks like C8517673505 N7062175 C8517673516 N7062178 C8517673527
1
5839
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure the no funny business can go on in the passed "path" that would produce a path not in the root (i.e. "..\..\dir1"). Here is my first stab at it, but...
1
1465
by: David Lozzi | last post by:
Hello, I'm looking for the best option to combine two XMLDocuments into a single document. I'm using ASP.Net using VB. I have a function that returns a dataset in XML which works great if there is a single call of the function, but at times I need to loop a few times and call the same function and return its data and combine each looped...
5
2989
by: jhutchings | last post by:
Hello everyone, I have a database where I collect shipment data from various tables. However, I have a problem. Whenever I want to see shipping data for orders that were set to ship on or before a certain date (in this case January 30th) the database will return 2 rows for an order as you can see below. Order ID: Line: Due Date: ...
5
1310
by: pjfarley3 | last post by:
Hi all, First-timer here, with a question about composing XML and XSL. I have a need to send one XML file with NO external server references to an end-user browser window; i.e., I would like to be able to do something like having the href in the "xml-stylesheet" declaration be a "local" reference, something like this: <?xml...
3
8197
by: Schroeder, AJ | last post by:
Hello group, I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco router in which I expect the script to return the interface number along with a small description of the interface type, like this: Array (
2
2358
by: nugz | last post by:
I want to combine 3 tables with like data then append it with a filter. Tables: NewStarts, Complaints, Memos Combine: Date, Address, Route, Pub, etc.... Then sort: previous 8 days, pub/freq for that day etc... I can already do the append filter, but I cant combine and then append. I tried a Union and did the combine.. but lack the...
1
1716
by: LSGKelly | last post by:
Hi all. I need to combine two fields that contain numbers that are in a currency format (Ex: $1,500 $3,500). When I combine them, I want them to look like this -- $1,500/$3,500. When I combine them in the query, they look like this 1500/3500. Is there a way to combine and retain the currency format? Thank you! Kelly
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.