Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2004, 09:45 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default Object is not a collection?!

hi, im new to ASP only been studying it for around 2months and im trying to use the session object to store values passed using a querystring This is the code

dim basketitem
basketitem = request.QueryString()
session.contents(basketitem)
for each item in session.contents("basketitem")
if isobject(session.contents("basketitem")) then
response.write session.contents("basketitem")
else
response.write "no items"
end if
'for each item in request.QueryString
'response.write " " & request.querystring(Item)
next

the idea is three values are collected using the querystring on one page then I want to add them to a kind of basket which i wanted to create using a session object. once the add to basket button is clicked the code show above is ran.

can anyone advise me where to go? this has to be completed by WEDS so any help is appreciated!

cheers
ASH:D

__________________
My new web design domain
www.askmultimedia.co.uk
 
Old January 26th, 2004, 11:54 AM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This bit of code worked for me, it involves creating a session level array in global.asa.

global.asa
<SCRIPT LANGUAGE="VBSCript" RUNAT="Server" >
Sub Session_OnStart
Session.basketItems()
End Sub
</SCRIPT>


your button on_Click
dim loopCount
loopCount = 1
If Request.QueryString.Count > 0 Then
For Each Item in Request.QueryString
Session("basketItems("&loopCount&")") = Request.QueryString(Item)
Response.Write(Session("basketItems("&loopCount&") ") & "<br />")
loopCount = loopCount + 1
Next
Else
Response.Write("No Items in basket")
End If
 
Old January 26th, 2004, 12:43 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

In the global.asa, it says that it doesnt support the code youve put?

do you not mean session("basketitems")=() ?????

thanks for the initial help
ASH

 
Old January 26th, 2004, 12:53 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

if you want to see the flow of the site im trying to make a basket for the address is:
http://www.kay-a.co.uk/FootballMemrobilia/FMindex.asp

go to the shirts and jerseys page and click any item to add, this then displays the values of the querystring. I have then added the code you sugested to the next page ../basket.asp?<%=request.querystring%>

do I need to add it to the button on the previous page " ADD ITEM TO BASKET "?
 
Old January 26th, 2004, 01:15 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

my appologies, the code will work without declaring the array in global.asa. The session will generate a cookie on the local machine and store the contets of the data there. Please make sure you don't have cookies turned off on your machine.

If you have the Beginning ASP 3.0 book see first paragraph on page 315.
 
Old January 26th, 2004, 02:55 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I visited your site, trash the first session array idea and go with this.

Have the "Add Item To Basket" link point to saveCookie.asp with the following:

<%
If Request.QueryString.Count > 0 Then
Response.Cookies("basketItems")("itemtitle") = Request.QueryString("itemtitle")
Response.Cookies("basketItems")("price") = Request.QueryString("price")
Response.Cookies("basketItems")("desc") = Request.QueryString("desc")
End If
Response.Redirect("basket.asp")
%>

Then add this to the basket.asp:
<body>
<%
If Request.Cookies("basketItems").HasKeys Then
    Response.Write("Item Title: " & Request.Cookies("basketItems")("itemtitle") & "<br />")
    Response.Write("Item Price: " & Request.Cookies("basketItems")("price") & "<br />")
    Response.Write("Item Descrition: " & Request.Cookies("basketItems")("desc"))
Else
    Response.Write("Nothing in your basket")
End If
%>
</body>

I think this will get the job done.
 
Old January 26th, 2004, 03:20 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

Thanks for that, but this only adds one item to the basket, i wanted to have multiple items in the basket?
is there a way?hehe!

cheers
ASH

 
Old January 26th, 2004, 06:34 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

saveCookie.asp
<%
Dim strCookieName

strCookieName = "Item"&Session("ItemNumber")

If Request.QueryString.Count > 0 Then
    Response.Cookies(strCookieName)("itemtitle") = Request.QueryString("itemtitle")
    Response.Cookies(strCookieName)("price") = Request.QueryString("price")
    Response.Cookies(strCookieName)("desc") = Request.QueryString("desc")
    Session("ItemNumber") = Session("ItemNumber") + 1
End If

Response.Redirect("basket.asp")

%>

basket.asp
<body>
<%
Response.Write("")
For Each Cookie in Request.Cookies
    If Request.Cookies(Cookie).HasKeys Then
        Response.Write("Item Title: " & Request.Cookies(Cookie)("itemtitle")&"<br />")
        Response.Write("Item Price: " & Request.Cookies(Cookie)("price")&"<br />")
        Response.Write("Item Description: " & Request.Cookies(Cookie)("desc")&"<br />")
        Response.Write("<a href='remove.asp?Item="&Cookie&"'>Remove This Item</a>")
    Else
        Response.Cookies(Cookie).Expires = Date() - 1000
    End If
Next
%>
</body>

remove.asp
<%
Response.Cookies(Request.QueryString("Item")).Expi res = Date() - 1000

Response.Redirect("basket.asp")

%>
 
Old January 26th, 2004, 08:07 PM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default

WOW!!!!!!

thank you sooooooooooo much

that works now, all i need to do is some calculations to get a running total and im done, you dont understand how much weight that has lifted from my back!!!! cheers!

If your ever in trouble, giv me a call i'll kill a moose for ya!!!haha

ASH






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can anybody help? Collection in C# naveenj .NET Framework 2.0 4 July 15th, 2007 09:34 PM
Return Collection object from a Web Method raybo .NET Web Services 2 June 17th, 2006 07:42 AM
VB Collection object Vs Disconnected Recordset Andypat Pro VB Databases 1 February 15th, 2005 06:57 PM
Collection in C# ? dedex C# 1 January 14th, 2005 04:51 PM
can collection object holds another arrar PurpleHaze VS.NET 2002/2003 0 July 10th, 2003 08:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.