Carrito De Compras

Páginas: 12 (2789 palabras) Publicado: 12 de noviembre de 2012
fuente
Shopping carts are very important and can many times be the most intimidating part of building an e-commerce site. This tutorial will show how easy it can be to implement a shopping cart using ASP.NET. Additionally, several basic explanations will be provided to help beginning ASP.NET programmers understand this wonderful framework.

Quick Overview of ASP.NET

Since ASP.NET hasn’tbeen covered too much on NETTUTS, I thought it would be good to include a brief overview of some of the things that distinguish it from other languages.
1. Code is compiled. The first time an ASP.NET page is requested over the web, the code is compiled into one or more DLL files on the server. This gives you the ability to just copy code out to the server and it gives you the speedbenefit of compiled code.
2. ASP.NET is an object oriented framework. Every function, property and page is part of a class. For example, each web page is its own class that extends the Page class. The Page class has an event that is fired when the webpage is loaded called the “Page Load Event”. You can write a function that subscribes to that event and is called on. The same principle applies toother events like the button click and “drop-down” “selected index changed” events.
3. The logic is separate from the design and content. They interact with each other, but they are in separate places. Generally, this allows a designer to design without worrying about function and it allows the programmer to focus on function without looking at the design. You have the choice of puttingthem both in the same file or in different files. This is similar to model-view-controller model.

If you are new to ASP.NET (and you have Windows), you can try it out for free You can download Visual Studio Express by visiting the ASP.NET website. Also, when you create a website locally on your machine, you can run the website at any time and Visual Studio will quickly start a server on yourcomputer and pull up your website in your default browser.
Step 1: Create the ShoppingCart Class
We need a place to store the items in the shopping cart as well as functions to manipulate the items. We’ll create a ShoppingCart class for this. This class will also manage session storage.
First, we have to create the App_Code folder. To do this, go to the “Website” menu, then “Add ASP.NETFolder”, and choose “App_Code.” This is where we’ll put all of our custom classes. These classes will automatically be accessible from the code in any of our pages (we don’t need to reference it using something similar to “include” or anything). Then we can add a class to that folder by right-clicking on the folder and choosing “Add New Item.”
Quick Tip: Regions in ASP.NET are really nice toorganize and group code together. The nicest thing about them is that you can open and close regions to minimize the amount of code that you are looking at or quickly find your way around a file.

view plaincopy to clipboardprint?
1. using System.Collections.Generic;  
2. using System.Web;  
3. /** 
4.  * The ShoppingCart class 
5.  * 
6. * Holds the items that are in the cart and provides methods for their manipulation 
7.  */  
8. public class ShoppingCart {  
9.     #region Properties  
10.     public List<CartItem> Items { get; private set; }  
11.     #endregion  
12.     #region Singleton Implementation  
13.     // Readonly properties can only be set in initialization or in a constructor  
14.    public static readonly ShoppingCart Instance;  
15.     // The static constructor is called as soon as the class is loaded into memory  
16.     static ShoppingCart() {  
17.         // If the cart is not in the session, create one and put it there  
18.         // Otherwise, get it from the session  
19.         if (HttpContext.Current.Session["ASPNETShoppingCart"] == null) {  
20....
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • carrito de compra
  • carrito compras
  • Carrito De Compras En Linea
  • Carrito de compras PHP
  • Carrito Compras
  • Carrito de compras
  • Carrito de la compra
  • Carrito de compras en asp

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS