Click to See Complete Forum and Search --> : Changing Cookie Values by calling class functions


SassanKZ
July 24th, 2002, 05:37 AM
I am developing an eShop with ASP.NET and my IDE is Visual Studio .NET. I want to use Cookie to keep Shop Cart information at client side. I also defined a class and some functions to work with them, for example adding an item to Cookie (Shop Cart), updating items and deleting an item.

But when I use these functions, no changes apply to the cookie value.
I think it is because the class doesn't have access to change Response and Request of Page.

Please let me know how I can solve this problem.

Here is the code I developed (Unnecessary parts are not shown.)
C# Class:
public class ShopCart
{
/*
...
*/

/******************** Cookie Remove_Name ******************/
// Removes an Item from Cookie
public void Remove_Name(HttpRequest thisReq, String Cookie_Name, String sName)
{
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;

MyCookieColl = thisReq.Cookies;

MyCookie = MyCookieColl[Cookie_Name];
if (MyCookie!=null)
{
if (MyCookie.Values.Get(sName)!=null)
{
MyCookie.Values.Remove(sName);
Response.Cookies.Add(MyCookie);
}
}
}
} // class

ASP.NET Call script:
ShopCart myShopCart = new ShopCarts.ShopCart();
myShopCart.Remove_Name(Request, "eShopCart", "item_01"

Look forward to hearing from you all.

Sassan