Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP form for a database 1

Status
Not open for further replies.

krymzon

Programmer
Joined
Feb 22, 2005
Messages
38
Location
CA
i'm running into this odd problem. i'm making and interface for a tiny database table using ASP. so, it reads the info, gets the first record no problem. then i have submit buttons at the bottom. i'm using HTML with a form method of post and an action of =GetCurentPage so i link back to the page i'm on. this is were my problem is. because i load the page every time after i press a submit button, i keep redeclaring my connection to the database, and therefore always linking up to my first record. now, this is a huge problem, becuase anytime i want to advance through my records, i would press next, but since next reloads the webpage, it will redeclare the conection variable and return to the start, therefor, i can't move through the records at all.
so, i was wondering if there was a method to find out whether the current page has been loaded durning the session. or maybe i'm approaching this form all wrong and there is a simpler way of doing it? either way, an help would be great.

there are 10 people in this world. those who know binary, and those who don't.
 
Suppose your form has a submit button as so:
[tt]<input type='submit' name='MySubmitButton' value='Go'>[/tt]


Then, at the top of your ASP, you can examine the Request object to see if any value was submitted for [tt]MySubmitButton[/tt] like this:
[tt]
IF (Len(Request.Form("MySubmitButton")) > 0) THEN
'This page is being "reloaded"
ELSE
'This is the first time the page was requested
END IF
[/tt]
 
ya, that actually works great. but i forgot to realise that since the page is loading everytime i click the submit button, i'm going to lose my variable that contains my database access. is there a way of making a variable that will continue to exist on the webpage, even after its been loaded. or, can you set a cookie to hold the databasename.execute(sql).

there are 10 people in this world. those who know binary, and those who don't.
 
wait, nevermind. i figured it out...i can submit the value i need throug the submit button.
its been a while since i've worked with asp, and starting it up again is alittle hard since i was working with C++ not to long ago...lol


there are 10 people in this world. those who know binary, and those who don't.
 
You could persist your object variables in session variables but that is generally known as a Very Bad Idea (TM) because it radically reduces the ability of your web site to scale to serve multiple users.

If you must save your place between page requests it is far better to save some text value(s) that will allow you to find your place the next time... In your case, perhaps the primary key to your database would be a good place to start.

As for how you save it, you could put it into a session variable but an even better way might be to put it into a hidden field on your HTML form like this:
[tt]
<input type='hidden' name='MyKeyField' value='<%= sFieldValue%>'>
<input type='submit' name='MySubmitButton' value='Go'>
[/tt]

 
yup, thats exactly what i'm doing right now as we speak. should be up and working by theend of the day which is nice. thanks for the help

there are 10 people in this world. those who know binary, and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top