473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Keeping random background

I created a public application based variable not within any procedure,
like so:

Partial Class lobbytimes_lobbytimes
Inherits System.Web.UI.Page

Public BackgroundImage As String

Protected Sub Page_Load(ByVal ..)

I then created a background image randomizer subroutine and placed that
into 'If not Page.IsPostback' decision on the page load routine, like so:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
LoadBackground()
End If

End Sub

And here's the LoadBackground routine:

Sub LoadBackground()

Randomize()
Dim imagegen(2) As String
Dim x As Short
x = CShort(Rnd() * 2)
imagegen(0) = "../lobbytimes/backgrounds/a1.gif"
imagegen(1) = "../lobbytimes/backgrounds/a2.gif"
imagegen(2) = "../lobbytimes/backgrounds/1.jpg"
BackgroundImage = imagegen(x)

End Sub

And on the aspx page, I put this:

<body background="<%Response.write(BackgroundImage)%>">

So, the problem is that when the page first loads, the random background
image loads fine. But, on any postback event (which there are several on
this application), the background image disappears and all that's left
is a white background (nothing).

Sure, I could place the LoadBackground routine under the Page_Load Sub,
but it would be annoying to see the background change 100 times a day.

I wanted the random image to load once and stay there while they used
the application.

Any ideas?

TIA,
Jim
Apr 11 '07 #1
1 1413
At the end of your LoadBackground function you should store the chosen
background value somewhere to persist it between postbacks.
Perhaps ViewState would be a good place. Alternately you might consider
Session state or perhaps a cookie.
Then in your Page_Load event you'd have code similar to this:

If Page.IsPostback() Then
'Load from ViewState
Else
'call LoadBackground function
End If

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>I created a public application based variable not within any procedure,
like so:

Partial Class lobbytimes_lobbytimes
Inherits System.Web.UI.Page

Public BackgroundImage As String

Protected Sub Page_Load(ByVal ..)

I then created a background image randomizer subroutine and placed that
into 'If not Page.IsPostback' decision on the page load routine, like so:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
LoadBackground()
End If

End Sub

And here's the LoadBackground routine:

Sub LoadBackground()

Randomize()
Dim imagegen(2) As String
Dim x As Short
x = CShort(Rnd() * 2)
imagegen(0) = "../lobbytimes/backgrounds/a1.gif"
imagegen(1) = "../lobbytimes/backgrounds/a2.gif"
imagegen(2) = "../lobbytimes/backgrounds/1.jpg"
BackgroundImage = imagegen(x)

End Sub

And on the aspx page, I put this:

<body background="<%Response.write(BackgroundImage)%>">

So, the problem is that when the page first loads, the random background
image loads fine. But, on any postback event (which there are several on
this application), the background image disappears and all that's left is
a white background (nothing).

Sure, I could place the LoadBackground routine under the Page_Load Sub,
but it would be annoying to see the background change 100 times a day.

I wanted the random image to load once and stay there while they used the
application.

Any ideas?

TIA,
Jim
Apr 11 '07 #2

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

Similar topics

10
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random...
6
by: lucy | last post by:
Hello comp.lang.js.I need a script to rotate a background image on each newpage load, given the id of the element and a list (array?)of 2 or more image paths ("img1.jpg", "img2.jpg", ...).Actually,...
1
by: Terry Haufler | last post by:
I am trying to swap/rotate random flash banners using the following Javascript code. I have 3 flash headers/banners. I can get it to open a page with a random header using...
12
by: Ivan Weiss | last post by:
Hey guys, quick question. I am trying to create a form that is always maximized and is an MDI Child. When another form opens I want it to open (windowed) on top of this form which is still...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
3
by: schof | last post by:
I am using the following code to call a random background image to be displayed on the far right hand side of the page ... <script type="text/javascript"> function random(n) { return...
4
by: Marina Levit | last post by:
I am trying to do some processing on a background thread while keeping the UI painting. However, this is a generic server side call routine - and it needs to block until the server side call...
2
by: Richard Sherratt | last post by:
I've inherited a system that was designed by someone with no understanding of database design. From the logical design point of view, there is no logical design. The physical design is a nightmare....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.