Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Can I combine ASP with external CSS?

Reply
Thread Tools

Can I combine ASP with external CSS?

 
 
Richard Speiss
Guest
Posts: n/a
 
      06-08-2004
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_IMAGES = 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_<%=intImageNumber%>.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


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      06-08-2004
Richard Speiss wrote on 08 jun 2004 in
microsoft.public.inetserver.asp.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)
 
Reply With Quote
 
 
 
 
Roland Hall
Guest
Posts: n/a
 
      06-08-2004
"Richard Speiss" wrote in message
news:%...
: 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_IMAGES = 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_<%=intImageNumber%>.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


 
Reply With Quote
 
Richard Speiss
Guest
Posts: n/a
 
      06-08-2004
Thanks but that didn't make a difference

Richard

"Evertjan." <> wrote in message
news:Xns95031B29448Feejj99@194.109.133.29...
> Richard Speiss wrote on 08 jun 2004 in
> microsoft.public.inetserver.asp.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)



 
Reply With Quote
 
Richard Speiss
Guest
Posts: n/a
 
      06-08-2004

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



 
Reply With Quote
 
Mark Schupp
Guest
Posts: n/a
 
      06-08-2004
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.contenttype 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" <> wrote in message
news:...
>
> 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
> >
> >

>
>



 
Reply With Quote
 
Lance Wynn
Guest
Posts: n/a
 
      06-09-2004
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" <> wrote in message
news:%...
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_IMAGES = 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_<%=intImageNumber%>.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



 
Reply With Quote
 
Richard Speiss
Guest
Posts: n/a
 
      06-09-2004
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" <> wrote in message
news:...
> 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" <> wrote in message
> news:%...
> 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_IMAGES = 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_<%=intImageNumber%>.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
>
>
>



 
Reply With Quote
 
Aaron [SQL Server MVP]
Guest
Posts: n/a
 
      06-09-2004
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.QueryString("i")%>.jpg);
....
}

Then call it like this:

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

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" <> wrote in message
news:%...
>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_IMAGES = 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_<%=intImageNumber%>.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
>
>



 
Reply With Quote
 
Aaron [SQL Server MVP]
Guest
Posts: n/a
 
      06-09-2004
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"//form[...]//input | //form[...]//select" or can I combine them? yawnmoth XML 2 08-18-2008 09:04 PM
Can I combine GUI & Applet? Martin Gregorie Java 6 12-02-2006 11:27 PM
Can I combine an EditItemTemplate and InsertItemTemplate? pjbates ASP .Net 1 05-02-2006 03:00 AM
Can not combine "if match=" and "when test" kmunderwood@charter.net XML 5 03-23-2005 11:29 AM
Can I combine both PagerStyle Modes (NumericPages and NextPrev) of the ASP.NET Datagrid Chris Simeone ASP .Net Datagrid Control 0 08-30-2004 03:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57