ASP.NET
  Home arrow ASP.NET arrow Page 5 - Back-end Management Tasks for an ASP.NET A...
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

Back-end Management Tasks for an ASP.NET AJAX Server-Centric Based Online Shopping Website
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-01-16

    Table of Contents:
  • Back-end Management Tasks for an ASP.NET AJAX Server-Centric Based Online Shopping Website
  • Moving Tree Nodes
  • Product Management
  • The Product Manage Page
  • Adding New Product
  • About Viewing Products

  • 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


    Back-end Management Tasks for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Adding New Product


    (Page 5 of 6 )


    Adding a New Product

    Before we start to discuss this function, let’s first see a snapshot of "ProductMain.aspx" (Figure 30) which is captured when the "Books" node is clicked.


    Figure 30—one of the run-time snapshots for product management

    Now, when the user clicks the "Add a New Product" button at the bottom, he will be navigated to another page, "AddProduct.aspx." The following Figure 31 shows one of its run-time snapshots.


    Figure 31—one of the run-time snapshot for adding product

    In designing this page, we’ve only used a little AJAX magic, as indicated from the above figure. For the user to more easily enter datetime data we provide him with an ASP.NET Calendarcontrol. How do we pop up the calendar control? One of the solutions is to resort to the ASP.NET AJAX Toolkit control named PopupControlExtender. How do we achieve the partial update effect when the user selects a new datetime from the calendar? For this, of course, we should seek help from the UpdatePanel.

    Now, let’s leap over the page initialization and examine the adding function. The following code shows the related click event handler for the "OK" button.

    protected void SureBtn_Click(object sender,EventArgs e){

    int nMaxPictureID = -1;

    //first insert image data into Pictures table then insert into Product
    with the known PictureID

    if (FileUpload1.PostedFile != null&& FileUpload1.PostedFile.FileName != "")

    {

    byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];

    HttpPostedFile Image = FileUpload1.PostedFile;

    Image.InputStream.Read(myimage, 0, (int)
    FileUpload1.PostedFile.ContentLength);

    Picture pic = new Picture();

    try{

    nMaxPictureID=pic.AddPicture("Image for product " + Name.Text,
    FileUpload1.PostedFile.ContentType, myimage);

    }

    catch (SqlException SQLexc) {

    Response.Write("Insert Failed. Error Details are: " + SQLexc.ToString());

    return;

    }

    }

    Product product = new Product();

    ///add data

    product.AddProduct(Name.Text,nCategoryID,Desn.Text,Sell.Text,

    DateTime.Parse(CreateDate.Text),DateTime.Parse(SellInDate.Text),

    Unit.Text,Int32.Parse(Quantity.Text),Int32.Parse(Upper.Text),

    Int32.Parse(Lower.Text),Decimal.Parse(InPrice.Text),

    Decimal.Parse(OutPrice.Text), nMaxPictureID, Remark.Text);

    ///display the info of the operating result

    Response.Write("<script>window.alert('You have succeeded in adding data.')
    </script>");

    }

    There are three things happening here. First, by clicking the FileUploadcontrol we browse and get the image file name. Then we dissect it, abstract the image data, store them into a byte array, and finally by invoking the AddPicture methodof the Picture classwe write the image data into the imagetyped field in the Pictures table. Second, we create an instance of the Product classand by calling its AddProductmethod we finally store all of the product info in the server-side database. Third, after everything is okay, we call "Response.Write(…)" 

    Will anything wrong be triggered due to the above UpdatePanel? No, it won’t. This is because it’s the last sentence—before this invocation all the possible asynchronous postbacks have taken place.

    When you click the "Edit" hyperlink in the above Figure 31, you will be navigated to another page, "EditProduct.aspx," to modify the selected product (where of course you can change the image file). Since the general logic of it is quite similar to the above "AddProduct.aspx" page, we don’t plan to examine the modifying function any further.

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - 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...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT