public static CartItemsList GetCart() { CartItemsList cart = (CartItemsList)HttpContext.Current.Session["Cart"]; if (cart == null) { HttpContext.Current.Session["Cart"] = new CartItemsList(); } return((CartItemsList)HttpContext.Current.Session["Cart"]); }
protected void Page_Load(object sender, EventArgs e) { // retrieve cart object from session state on every postback cart = CartItemsList.GetCart(); // on initial page load, add cart items to list control if (!IsPostBack) { this.DisplayCart(); } }
protected void BtnAdd_Click(object sender, EventArgs e) { if (IsValid) { //get cart from session state and selected item from cart CartItemsList cart = CartItemsList.GetCart(); if (selectedMobile != null) { cart.AddItem(selectedMobile, Convert.ToInt32(txtQuantity.Text)); Response.Redirect("~/Cart.aspx"); } } }