Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. cannot do add to cart function

cannot do add to cart function

Scheduled Pinned Locked Moved ASP.NET
helpasp-netdebugging
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    setengah
    wrote on last edited by
    #1

    first, i'm sorry i'm newbie here and newbie in aspnet. i learn some code from ebook but it's not working. and i'm really sorry too because my english is bad. when i debug my project its working fine, and i try to add item to my shopping cart its not show any error but the button do not work, its ike the product page only reload. i hope i can find the answer here. thanks for help. here the code CartAccess.cs

    using System;
    using System.Web;
    using System.Data;
    using System.Data.Common;

    /// <summary>
    /// Supports Shopping Cart functionality
    /// </summary>
    public class CartAccess
    {
    public CartAccess()
    {
    //
    // TODO: Add constructor logic here
    //
    }

    // returns the shopping cart ID for the current user
    private static string shoppingCartId
    {
        get
        {
            HttpContext context = HttpContext.Current;
            string cartId;
            {
                // check if the cart ID exists as a cookie
                if (context.Request.Cookies\["Delta\_CartID"\] != null)
                {
                    // return the id
                    //return context.Request.Cookies\["Delta\_CartID"\].Value;
                    cartId = context.Request.Cookies\["Delta\_CartID"\].Value;
                    return cartId;
    
    
                }
                else
                // if the cart ID doesn't exist in the cookie as well, generate a new ID
                {
                    // generate a new GUID
                    //Guid tempGuid = Guid.NewGuid();
                    //context.Response.Cookies\["Delta\_CartID"\].Value = tempGuid.ToString();
                    cartId = Guid.NewGuid().ToString();
                    // create the cookie object and set its value
                    HttpCookie cookie = new HttpCookie("Delta\_CartID", cartId);
                    // set the cookie's expiration
                    int howManyDays = deltaconfig.CartExpireDays;
                    DateTime currentDate = DateTime.Now;
                    TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0);
                    DateTime expirationDate = currentDate.Add(timeSpan);
                    cookie.Expires = expirationDate;
                    // set the cookie on the client's browser
                    context.Response.Cookies.Add(cookie);
                    // return the CartID
                    return cartId.ToString();
                }
            }
        }
    }
    
    // Add a new s
    
    T 1 Reply Last reply
    0
    • S setengah

      first, i'm sorry i'm newbie here and newbie in aspnet. i learn some code from ebook but it's not working. and i'm really sorry too because my english is bad. when i debug my project its working fine, and i try to add item to my shopping cart its not show any error but the button do not work, its ike the product page only reload. i hope i can find the answer here. thanks for help. here the code CartAccess.cs

      using System;
      using System.Web;
      using System.Data;
      using System.Data.Common;

      /// <summary>
      /// Supports Shopping Cart functionality
      /// </summary>
      public class CartAccess
      {
      public CartAccess()
      {
      //
      // TODO: Add constructor logic here
      //
      }

      // returns the shopping cart ID for the current user
      private static string shoppingCartId
      {
          get
          {
              HttpContext context = HttpContext.Current;
              string cartId;
              {
                  // check if the cart ID exists as a cookie
                  if (context.Request.Cookies\["Delta\_CartID"\] != null)
                  {
                      // return the id
                      //return context.Request.Cookies\["Delta\_CartID"\].Value;
                      cartId = context.Request.Cookies\["Delta\_CartID"\].Value;
                      return cartId;
      
      
                  }
                  else
                  // if the cart ID doesn't exist in the cookie as well, generate a new ID
                  {
                      // generate a new GUID
                      //Guid tempGuid = Guid.NewGuid();
                      //context.Response.Cookies\["Delta\_CartID"\].Value = tempGuid.ToString();
                      cartId = Guid.NewGuid().ToString();
                      // create the cookie object and set its value
                      HttpCookie cookie = new HttpCookie("Delta\_CartID", cartId);
                      // set the cookie's expiration
                      int howManyDays = deltaconfig.CartExpireDays;
                      DateTime currentDate = DateTime.Now;
                      TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0);
                      DateTime expirationDate = currentDate.Add(timeSpan);
                      cookie.Expires = expirationDate;
                      // set the cookie on the client's browser
                      context.Response.Cookies.Add(cookie);
                      // return the CartID
                      return cartId.ToString();
                  }
              }
          }
      }
      
      // Add a new s
      
      T Offline
      T Offline
      T M Gray
      wrote on last edited by
      #2

      Having all of the methods of the cart as static is a bad idea. You are also throwing away the return values. If CartAccess.AddItem returns a bool you should be doing something with it. It could be as simple as setting the text of a label with "added to cart" or "oops something bad happened". I am guessing you would be getting a false and that it has something to do with your database connection. To get detailed info about what went wrong, either remove the try/catch around the DataAccess calls, or in the catch, change it to catch(Exception ex) and set a label with ex.Message. Your English is not bad at all.

      F 1 Reply Last reply
      0
      • T T M Gray

        Having all of the methods of the cart as static is a bad idea. You are also throwing away the return values. If CartAccess.AddItem returns a bool you should be doing something with it. It could be as simple as setting the text of a label with "added to cart" or "oops something bad happened". I am guessing you would be getting a false and that it has something to do with your database connection. To get detailed info about what went wrong, either remove the try/catch around the DataAccess calls, or in the catch, change it to catch(Exception ex) and set a label with ex.Message. Your English is not bad at all.

        F Offline
        F Offline
        Fayu
        wrote on last edited by
        #3

        5 for you because of your etiquette and good manners!!!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups