473,320 Members | 2,112 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,320 software developers and data experts.

variable passing in web applications

1
Hey all
I have a vb.net/asp.net dynamic website connected to an access database using a oledb connection. I use a datareader to retrieve the results of a query and iterate through the results using the read() method.
The page in question is a string matching search page (its a photo site and the photos have associated tags) that may return multiple results. I wish to display the first picture match and its details and then have a button that can be clicked to go to the next match and so on. So I need to call the read method on the datareader in a separate button click to the one in which it is created. But the reference to the datareader seems to get garbage collected as soon as the original click method completes.
So I tried instead to use a while loop to call the read method to build an array full of the data I needed from the reader and then read the next index of the array each time the nextbutton_click method runs (which id track with a static variable or something). But I cannot work out how to access this array from a separate method. It cannot be passed in as a parameter because its a button click, and needs to be called at random not immediately after the search button is pressed. Ive also tried using a single method that both the search button and the next button call to build/access the array depending on the integer passed in (like a switch) but of course if the array and other variables are defined in this method then they gets reinitialised everytime its called (thanks to the compiler not allowing variables defined in an if statement to be called outside it)

in summary: if I build an array (or any variable) in one method and wish to access it in another but cannot pass it to this second method as a parameter and cant use global variables (or can I?), what do I do?
there must be a simple way of doing this in web applications
or is this simply a limitation of this type of programming?

thanks bcshaw
Jun 1 '07 #1
2 1477
dip_developer
648 Expert 512MB
Hey all
I have a vb.net/asp.net dynamic website connected to an access database using a oledb connection. I use a datareader to retrieve the results of a query and iterate through the results using the read() method.
The page in question is a string matching search page (its a photo site and the photos have associated tags) that may return multiple results. I wish to display the first picture match and its details and then have a button that can be clicked to go to the next match and so on. So I need to call the read method on the datareader in a separate button click to the one in which it is created. But the reference to the datareader seems to get garbage collected as soon as the original click method completes.
So I tried instead to use a while loop to call the read method to build an array full of the data I needed from the reader and then read the next index of the array each time the nextbutton_click method runs (which id track with a static variable or something). But I cannot work out how to access this array from a separate method. It cannot be passed in as a parameter because its a button click, and needs to be called at random not immediately after the search button is pressed. Ive also tried using a single method that both the search button and the next button call to build/access the array depending on the integer passed in (like a switch) but of course if the array and other variables are defined in this method then they gets reinitialised everytime its called (thanks to the compiler not allowing variables defined in an if statement to be called outside it)

in summary: if I build an array (or any variable) in one method and wish to access it in another but cannot pass it to this second method as a parameter and cant use global variables (or can I?), what do I do?
there must be a simple way of doing this in web applications
or is this simply a limitation of this type of programming?

thanks bcshaw
yes you can use a global variable......store the array in a Session variable
Jun 1 '07 #2
Plater
7,872 Expert 4TB
Or make your array global or just page-global. I use a few page globals usually, pretty easy to handle and not to demanding on resources
Jun 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bryan Martin | last post by:
I have a object that is created in a seperate domain which needs to be passed back to the parent class. Because this object is created in a seperate domain if I try to pass the object back to the...
3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
7
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
3
by: A Ward | last post by:
I am trying to find a way to have multiple seperate ASP.Net applications where I can response.redirect() to a second web application and pass information. From what I have tried: * HTTP-GET - I...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
8
by: lovecreatesbeauty | last post by:
Hello experts, I have seen following the code snippet given by Marc Boyer (with slight changes by me for a better format), and have doubts on it. I am so grateful if you can give me your kindly...
3
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on...
4
by: aramsey | last post by:
I have a javascript program that works fine under Firefox and on IE when running XP, but is having a problem with IE running under Windows 2000 Pro. On my personal XP development machine I have...
8
by: Gerhard Fiedler | last post by:
Hello, I'm not sure whether this is a problem or not, or how to determine whether it is one. Say memory access (read and write) happens in 64-bit chunks, and I'm looking at 32-bit variables....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.