473,850 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not taking cookie and adding data

I am working with a shopping cart (I am suing a book). At this point I
am trying to add the cartID, the productID, quantity and time. At the
same time it is supposed to add a cookie. When I click the add to cart
button it gives me a postback but does not enter data in the database
or add the cookie. I have tried to work with permissions. Since it is
on my local machine I have added permission to everything I can think
of. Here is the code. I would love some help.

One thing I have considered is that my example is using a button in a
datalist while I am in a datagrid. Can that be an issue?

The button is in a template column of the datagrid. Here is the code

Private Sub datagrid1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
datagrid1.ItemC ommand
'in the command arguement of ther button that was clicked
'in the datagrid contains the productID
Dim intProductID As String = e.CommandArgume nt
'add the productto the shopping cart
ShoppingCart.Ad dProduct(intPro ductID)
End Sub

It is referring to a class called ShoppingCart.ad dproduct which is the

Public Shared Function AddProduct(ByVa l intProductID As String)
' Create the connection object
Dim connection As New SqlConnection(c onnectionString )
' Create and initialize the command object
Dim command As New SqlCommand("Add ProductToCart", connection)
command.Command Type = CommandType.Sto redProcedure
' Add an input parameter and supply a value for it
command.Paramet ers.Add("@CartI D", SqlDbType.Char, 36)
command.Paramet ers("@CartID"). Value = shoppingCartID
' Add an input parameter and supply a value for it
command.Paramet ers.Add("@intPr oductID", SqlDbType.Int)
command.Paramet ers("@intProduc tID").Value = intProductID
' Open the connection, execute the command, and close the
connection.Open ()
command.Execute NonQuery()
connection.Clos e()
End Try
End Function
I am also trying to take a cookie at the same time. It is not working
at all.

Here is the cookie code.

Private Shared ReadOnly Property shoppingCartID( )
Dim context As HttpContext = HttpContext.Cur rent

' If the JokePoint_CartI D cookie doesn't exit
' on client machine we create it with a new GUID
If context.Request .Cookies("dough boys_cartID") Is Nothing
' Generate a new GUID
Dim CartID As Guid = Guid.NewGuid()
' Create the cookie and set its value
Dim cookie As New HttpCookie("dou ghboys_cartID",
CartID.ToString )
' Current Date
Dim currentDate As DateTime = DateTime.Now()
' Set the time span to 10 days
Dim ts As New TimeSpan(10, 0, 0, 0)
' Expiration Date
Dim expirationDate As DateTime = currentDate.Add (ts)
' Set the Expiration Date to the cookie
cookie.Expires = expirationDate
' Set the cookie on client's browser
context.Respons e.Cookies.Add(c ookie)
' return the Cart ID
Return CartID.ToString ()
' return the value stored in JokePoint_CartI D
context.Request .Cookies("dough boys_CartID").V alue
End If
End Get
End Property

Mar 15 '06 #1
0 966

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page (same folder). The cookie is not received. Can someone explain why? I worked around this by adding a cache-control header with a value of no-cache. This fixes the problem. Unfortunately that causes another problem with Internet Explorer...
by: Christoph Pieper | last post by:
Hi, we've the following problem : We have an asp-application which sets the cookie on first login. The cookie will never be touched during user access. The user can work the whole day, but after 6 to 7 hours, the cookie get 2-4 new asp-sessionid's thus overwriting the very first entries in the cookie. Does anyone had the same problem or has a solution. The server is a w2003 enterprise the client has windows xp sp2.
by: Alec S. | last post by:
Hi, I'm using JavaScript and Cookies for some customization in a web page. There may be several values in the cookie with names that are not known at runtime. I need a way of deleting them. For example, if my site is www.test.com and the cookie contains: label1 fob
by: RCHENG | last post by:
Hi guys, I am pretty new to network programming with c#, and is having problem using cookie with HTTPWEBREQUEST object. My question involves sending a request with cookie. What I am trying to do is to authenticate myself in a browser, look at the HTTP header using a sniffer, and simulate the http request but with different POST data. I do know what my cookie is from the http sniffer but I can't seem to get it to put into HTTPWEBREQUEST...
by: Ben Amada | last post by:
Every time a user visits a particular page, I'm using the code below to add a cookie that expires in 1 day. My question is, a user may visit this page a few times within one day. Before adding the cookie each time, do I need to delete the previous cookie? Or will the new cookie just overwrite the old cookie? I'm trying to avoid having multiple cookies on the user's machine -- just one. FYI, the cookie "name" will be the same every...
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
by: Laura K | last post by:
I am working with a shopping cart (I am suing a book). At this point I am trying to add the cartID, the productID, quantity and time. At the same time it is supposed to add a cookie. When I click the add to cart button it gives me a postback but does not enter data in the database or add the cookie. I have tried to work with permissions. Since it is on my local machine I have added permission to everything I can think of. Here is the...
by: D. | last post by:
Hi, I defined some cookies in order to pass values between pages in my application. The problem is that when i request them with: cookie = Request.Cookies("mycookie") x = cookie.Value (suppose the value = 'yes') Response.Write(x) i get:
by: flutetones | last post by: Here is a link to my server. I have an issue that doen't make sense. What's hapening is this . . . What's going right . . .
by: fran7 | last post by:
Hi, I have this very nice link tracker script that works a treat. The only thing is it doesnt restrict repeat clicking. Is there a simple method to add a cookie feature to this so that people cannot vote twice. I prefer cookies over ip recording. Any pointers would be a great help. %@ Language=VBScript %> <% Option Explicit ' Never code without it!
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...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.