473,651 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keeping random background

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

Partial Class lobbytimes_lobb ytimes
Inherits System.Web.UI.P age

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.EventArg s) 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="<%R esponse.write(B ackgroundImage) %>">

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 1435
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*******@hotm ail.comwrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
>I created a public application based variable not within any procedure,
like so:

Partial Class lobbytimes_lobb ytimes
Inherits System.Web.UI.P age

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.EventArg s) 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="<%R esponse.write(B ackgroundImage) %>">

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
2494
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 spots on the webpage. with a delay timer on them, so they keep changing as the page is open. Not random each time the page is loaded. If anyone can help it would be greatly appreaciated, I have tried many of
6
2095
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, depending on how I write the HTML, I guess I'dneed the script to set style.backgroundImage or src.I'd need to run it on a few elements, something like:setRandomBgImg('thingy1', ('img1a','img1b', ...) )setRandomBgImg('thingy2', ('img2a','img2b',...
1
5278
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 document.write(randomHeader) in the chooseHeader() function, but the rest of the page doesn't get displayed with that approach. Instead, what I would like to do is comment the document.write(randomHeader) line, and use the random reference I have in the table cell...
12
2324
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 maximized. Is this possible? -Ivan *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
2747
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
3
2725
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 Math.floor((Math.random() % 1) * n); } document.documentElement.style.background="url('photo"++".jpg') repeat-y 890px 0 background-attachment: fixed" </script> This is working fine in explorer - but does not bring up the image in safari or mozilla ... any...
4
1864
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 completes. So the idea is, a server side call begins, it gets spun off on another thread to keep the UI painting - but, the code flow cannot return to the caller until the server side call completes, because the caller expects the data. The only way...
2
2043
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. e.g. there are no relationships between tables and foreign keys appear to have been sprinkled at random like confetti. As an example, the Employer - Employee - Contract - Expense hierarchy has EmployerID in the Expense table. That's the...
0
8349
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8795
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7296
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.