using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Globalization; /* ===================================================================== File: AddToCart.aspx.cs for Adventure Works Cycles Storefront Sample Summary: This user control adds the identified product to the user's shopping cart, and then immediately redirects to the ShoppingCart page (this avoids problems where a user hits "refresh" and accidentally adds another product to the cart). Date: June 16, 2003 --------------------------------------------------------------------- This file is part of the Microsoft SQL Server Code Samples. Copyright (C) Microsoft Corporation. All rights reserved. This source code is intended only as a supplement to Microsoft Development Tools and/or on-line documentation. See these other materials for detailed information regarding Microsoft code samples. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. ======================================================= */ namespace Microsoft.Samples.SqlServer { public partial class AddToCart_aspx : System.Web.UI.Page { // Page events are wired up automatically to methods // with the following names: // Page_Load, Page_AbortTransaction, Page_CommitTransaction, // Page_DataBinding, Page_Disposed, Page_Error, Page_Init, // Page_Init Complete, Page_Load, Page_LoadComplete, Page_PreInit // Page_PreLoad, Page_PreRender, Page_PreRenderComplete, // Page_SaveStateComplete, Page_Unload protected void Page_Load(object sender, EventArgs e) { if (Request.Params["ProductID"] != null) { ShoppingCartDB cart = new ShoppingCartDB(); // Obtain current user's shopping cart ID String cartId = cart.GetShoppingCartId(); // Add Product Item to Cart cart.AddItem(cartId, Int32.Parse(Request.Params["ProductID"], CultureInfo.InvariantCulture), 1); } Response.Redirect("ShoppingCart.aspx"); } } }