p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > ASP Forms
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 6th, 2004, 05:49 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP Form Data - Using Session Variables

How do I convert form variables to Session variables?

Say, for instance, that the user clicked on a checkbox and submitted the form, and the checkbox they submitted was called "item1" in the form handler. I know that when I do the following in the form handler, the following works to output the data:

<%
dim item1,item2

item1 = request.querystring("checkbox1")
item2 = request.querystring("checkbox2")

if item1="checkbox" then response.write("The item you selected is "&item1)
if item2="checkbox" then response.write("The item you selected is "&item2)

%>

This works perfectly, but if they close the page, everything goes away. I want what they selected to carry with them until they manually close the session by checking out.

How would I summarize all data from the form and attach/convert it to their session, so when they go somewhere else in my site, the results from the previous form sticks with them? Realistically, how could I take variable "item1" and have it apply to a final form?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #2 (permalink)  
Old May 7th, 2004, 03:48 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Hi there,

You can simply save the values you want to Session variables, and later use them again:
Code:
If item1 = "checkbox" Then 
  Session("CheckBox1") = True
End If
Later in your form, you can use this code to preselect the item again:
Code:
Dim CheckedString
If Session("CheckBox1") = True Then
  CheckedString = " checked=""checked"""
End If

...

<form>
<input name="checkbox" type="checkbox" value="checkbox"<%=CheckedString%> />
</form>
When the page is loaded, CheckedString will get a value if the Session value equals True. The value of " checked=""checked"" for the CheckedString variable will end up in the checkbox like this:

<input name="checkbox" type="checkbox" value="checkbox" checked="checked" />

causing the checkbox to be selected.

The example I gave is quite verbose, to demonstrate the concept. In reality, you can compact the code a bit by saving the checked="checked" string as the Session variable's value or by using Response.Write to write out the checkbox inside the If statement.
All solutions would work equally well, so it's just a matter of personal preference.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: 3 Libras by A Perfect Circle (Track 18 from the album: Thirteenth Step) What's This?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net pages share session variables...?? jakeriggs ASP.NET 2.0 Basics 1 April 23rd, 2008 10:10 PM
ASP SESSION CONTENTS VARIABLES CAN'T BE CHANGED Epevas Classic ASP Components 8 January 30th, 2006 09:38 AM
session variables in asp to asp.net marvz ASP.NET 2.0 Basics 0 August 1st, 2005 04:09 AM
session variables and form parameters tacky BOOK: Beginning ASP 3.0 0 January 16th, 2005 09:36 PM
Passing Session Variables(ASP.NEt) to Jscript ank2go JSP Basics 1 February 26th, 2004 09:53 PM



All times are GMT -4. The time now is 12:51 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc