ASP.NET
  Home arrow ASP.NET arrow Page 5 - Order-Related Modules for an ASP.NET AJAX ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-12-26

    Table of Contents:
  • Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website
  • Behind the Scenes
  • More Behind the Scenes Code
  • Web Handler
  • Buying Goods
  • Viewing the Shopping Cart
  • Page Initialization

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Buying Goods


    (Page 5 of 7 )

    After clicking the "Add to shopping cart" button, the related item can be put into the shopping cart, all of which is finished within the ProductView_RowCommand click event handler. In conclusion, the function will accomplish the following tasks:

    1. If there are no products inside the shopping cart, create an instance of the  OrderInfo(i.e. order) class which is used to save the cart related info;
    2. Obtain information about the product and create an instance of the OrderItemInfo(i.e. item) class to save this product-related info;
    3. Add the item objectinto the OrderItemList listof the order object;
    4. Update the info of the cart;
    5. If there are already products inside the shopping cart, get the order object used to save the cart-related info from the Session system variable;
    6. Obtain info of the product and create an instance of the OrderItemInfo(i.e. item) class to save this product-related info;
    7. Search from inside the order objectsub items that contain the same product as that inside the item project, and update the sub items info;
    8. Update the shopping cart.


    The following lists the complete code for the ProductView_RowCommand function:

    protected void ProductView_RowCommand(object
    sender,GridViewCommandEventArgs e){

    OrderItemInfo item = null;

    OrderInfo order = null;

    if(Session[Session.SessionID + OrderForm.Cart] == null) {

    item = GetOrderItemInformation(e);

    if(item == null) {

    ScriptManager.RegisterStartupScript(Page, GetType(), "script1",

    "alert('Data Error!');", true);

    return;

    }

    order = new OrderInfo();

    order.OrderItemList.Add(item);

    order.TotalMoney = item.Price;

    order.TotalNumber = item.Number;

    Session[Session.SessionID + OrderForm.Cart] = order;

    }

    else{

    order = (OrderInfo)Session[Session.SessionID + OrderForm.Cart];

    item = GetOrderItemInformation(e);

    if(item == null) {

    ScriptManager.RegisterStartupScript(Page, GetType(), "script2",

    "alert('Data Error!');", true);

    return;

    }

    int i = 0;

    for(i = 0; i < order.OrderItemList.Count; i++){

    if(item.ProductID == ((OrderItemInfo)order.OrderItemList[i]).ProductID) {

    ((OrderItemInfo)order.OrderItemList[i]).Number++;

    ((OrderItemInfo)order.OrderItemList[i]).ItemTotalMoney +=
    item.ItemTotalMoney;

    break;

    }

    }

    if(i == order.OrderItemList.Count) {

    order.OrderItemList.Add(item);

    }

    order.TotalNumber++;

    order.TotalMoney += item.Price;

    Session[Session.SessionID + OrderForm.Cart] = order;

    }

    ScriptManager.RegisterStartupScript(Page, GetType(), "script3",

    "alert('You have succeeded in adding the selected goods into the shopping
    cart!');", true);

    }

    For brevity, we omit the code listing for the GetOrderItemInformation helper function.

    In addition, there are several issues that deserve to be discussed. First, because when we get the product information, the row index of the ProductView controlhas to be used, at the earlier event (RowCreated) of the ProductView controlwe put the index number of the product into the CommandArgument propertyof the buyBtn button(which is the IDproperty of the "Add to shopping cart" button). Here's the related code:

    protected void ProductView_RowCreated(object sender,GridViewRowEventArgs
    e){

    if(e.Row.RowType == DataControlRowType.DataRow) {

    Button buyBtn = (Button)e.Row.FindControl("BuyBtn");

    if(buyBtn != null) {

    buyBtn.CommandArgument = e.Row.RowIndex.ToString();

    }

    }

    }

    Second, in traditional ASP.NET applications most of us like to use 'Response.Write("<script>window.alert('....')</script>");' to tell users the result of the current operation. However, due to leveraging the ASP.NET AJAX server control named UpdatePanelto enclose the GridView control we can not use that any more, or else we will meet some error like the one displayed in Figure 16.


    Figure 16-an error occurs when we use 'Response.Write(...);' inside UpdatePanel control to give some clue to the users

    Therefore, we have to resort to a static function named RegisterStartupScriptof the ScriptManager control. Here is an example of what happens when the "adding" operation is successful.

    ScriptManager.RegisterStartupScript(Page, GetType(), "script3",

    "alert('You have succeeded in adding the selected goods into the shopping
    cart!');", true);

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek