ASP.NET
  Home arrow ASP.NET arrow Page 4 - Drag and Drop Programming in Microsoft ASP...
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Drag and Drop Programming in Microsoft ASP.NET AJAX
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 9
    2007-06-20

    Table of Contents:
  • Drag and Drop Programming in Microsoft ASP.NET AJAX
  • Inner workings of the client side drag
  • Create an ASP.NET AJAX CTP-Enabled Web Site
  • Write the Web Service

  • 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


    Drag and Drop Programming in Microsoft ASP.NET AJAX - Write the Web Service


    (Page 4 of 4 )

    By using Web Service, we can utilize the standard way to wrap the basic database operation and supply the data to the client side. Right click the project, choose "Add new item" and create a new Web Service named ShoppingService.asmx. Next, we will open the ShoppingService.cs file and create the required web methods.

    First, as required by the framework, we must put the ScriptService attribute before the Web Service so that the MS AJAX JavaScript framework can call it correctly. The following is the key code snippet:

     

    [System.Web.Script.Services.ScriptService]

    public class ShoppingService : System.Web.Services.WebService

     

    Next, we should define a private field, Pets, to represent all the pet information in the online store:

     

    private List<Pet> _pets;

    private List<Pet> Pets

    {

       get

       {

         if (_pets == null)

         {

           _pets = new List<Pet>();

           _pets.Add(new Pet(1, "Flex", "Cat","Gray",390));

           _pets.Add(new Pet(2, "Fido", "Dog", "Brown", 490));

           _pets.Add(new Pet(3, "Rover", "Dog", "Brown", 550));

           _pets.Add(new Pet(4, "Daisy", "Dog", "Black and White", 390));

           _pets.Add(new Pet(5, "Polly", "Cat", "Green", 490));

         }

         return _pets;

       }

    }

     

    Note here, just for the purposes of the demo, we've hard coded some commodities instead of inquiring for the information from the database. In real world scenarios, this kind of data is typically acquired from inside some database.

    Next, we are to define the Pet class as an OOP wrapper of the pet information, with the fields called Id, Name and Price representing the identification, name and price properties of the pet, respectively:

     

    public class Pet

    {

       private int _id;

       public int Id

       {

         get { return _id; }

         set { _id = value; }

       }

       private string _name;

       public string Name

       {

         get { return _name; }

         set { _name = value; }

       }

       private int _category;

       public int Category

       {

         get { return _category; }

         set { _category = value; }

       }

       private int _color;

       public int Color

       {

         get { return _color; }

         set { _color = value; }

       }

       private int _price;

       public int Price

       {

         get { return _price; }

         set { _price = value; }

       }

       public Pet()

       {

       }

       public Pet(int id, string name, string category, string color, int price)

       {

         this._id = id;

         this._name = name;

         this._category = category;

         this._color = color;

         this._price = price;

       }

    }

     

    From now on, we'll define the necessary WebMethods. The first one named GetPets() is used to return all current commodities stored in the warehouse:

     

    [WebMethod]

    public Pet[] GetPets()

    {

       return Pets.ToArray();

    }

     

    As is hinted from the above figures, we should also define a WebMethod named Order which is used to process pet information posted from the client side shopping cart and then return the final result. Here, the one parameter of the Order method is a Dictionary structure; the Key corresponds to the Id of the pet and Value to the number of the selected pet inside the shopping cart:

     

    [WebMethod]

    public string Order(Dictionary<string, int> petsToBeOrdered)

    {

       // total number of pets

       int totalQuantity = 0;

       // total price of pets

       int totalPrice = 0;

       //figure out the total price of all the pets to buy

       foreach (KeyValuePair<string, int> petQuantity in petsToBeOrdered)

       {

         foreach (Pet pet in Pets)

         {

           if (pet.Id.ToString() == petQuantity.Key)

           {

             totalQuantity += petQuantity.Value;

             totalPrice += (pet.Price * petQuantity.Value);

             break;

           }

         }

       }

       //return the dealt result

       return string.Format(

         "You've ordered {0} pet(s) at the total price {1}. Thank you!",

         totalQuantity,

         totalPrice

       );

    }

     

    That's all we have room for right now. In the second part, we will look at the really interesting aspects -- defining the drag and drop behaviors to achieve our goal. You won't want to miss it!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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