473,721 Members | 1,810 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
behind.

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
following

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
Try
connection.Open ()
command.Execute NonQuery()
Finally
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( )
Get
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
Then
' 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 ()
Else
' return the value stored in JokePoint_CartI D
Return
context.Request .Cookies("dough boys_CartID").V alue
End If
End Get
End Property

Mar 15 '06 #1
0 1112

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

Similar topics

18
8844
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...
14
3271
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
1
10852
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...
3
1844
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...
3
11120
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...
0
960
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...
4
1673
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:
1
1602
by: flutetones | last post by:
http://67.189.52.24/~metafusionserver/public_html/training.php 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 . . .
2
1629
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!
0
8837
marktang
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...
0
8728
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,...
0
9366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9214
jinu1996
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...
1
9130
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,...
0
9059
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6668
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5977
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2572
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.