ASP.NET
  Home arrow ASP.NET arrow Delving Deeper into Drag and Drop Programm...
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

Delving Deeper into Drag and Drop Programming in Microsoft ASP.NET AJAX
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-06-25

    Table of Contents:
  • Delving Deeper into Drag and Drop Programming in Microsoft ASP.NET AJAX
  • Write a Behavior: ShoppingCartBehavior to make the shopping cart droppable
  • Coding the web page
  • Obtaining the list of the pets to sell via Web Service
  • Dealing with the order via 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


    Delving Deeper into Drag and Drop Programming in Microsoft ASP.NET AJAX


    (Page 1 of 5 )

    In the first part of this article, we summarized the multiple solutions suggested by MS AJAX, and began building an example to show some of these solutions in action. In the conclusion, we continue exploring this rather complex example to show you the under-the-hood workings of all the client side drag and drop solutions within the MS AJAX framework.
    A downloadable .rar file is available for this article.

    Define a Behavior: DraggableProductBehavior to drag the product

    With the analysis I gave you before, you can see that this DraggableProductBehavior is virtually a class that has to implement the Sys.Preview.UI.IDragSource interface. We'll attach this behavior to the related HTML DOM element that identifies the product to make it draggable.

    Now, just create a new JavaScript file named ShoppingCart.js, and we should register the namespace ShoppingCartNamespace:

     

    Type.registerNamespace("ShoppingCartNamespace");

     

    Next, define the constructor of this class, as well as some necessary fields:

     

    ShoppingCartNamespace.DraggableProductBehavior = function(element) {

      // initialize the base class

      ShoppingCartNamespace.DraggableProductBehavior.initializeBase(this, [element]);

      // the event handler for mouse down

      this._mouseDownHandler = Function.createDelegate(this, this._handleMouseDown);

     

      // the pet represented by the draggable object

      this._pet = null;

     

      // the translucent element(s) dragged with the mouse moving

      this._visual = null;

    }

     

    Next comes the prototype definition of the DraggableProductBehavior class:

     

    ShoppingCartNamespace.DraggableProductBehavior.prototype = {

      //methods within interface IDragSource

      // return the data type of the draggable object--"Pet"

      get_dragDataType: function() {

        return "Pet";

      },

      // Obtain data from the draggable object

      getDragData: function(context) {

        return this._pet;

      },

      // Set the mode of the draggable object

      get_dragMode: function() {

        return Sys.Preview.UI.DragMode.Copy;

      },

      //call it when the dragging starts

      onDragStart: function() {

      },

      //call it when the dragging is going on

      onDrag: function() {

      },

      //call it when the dragging is over

      onDragEnd: function(canceled) {

        if (this._visual)

          this.get_element().parentNode.removeChild(this._visual);

      },

      //property pet

      get_product: function(pet) {

        return this._pet;

      },

      set_pet: function(pet) {

        this._pet = pet;

      },

      // initialize

      initialize: function() {

        $addHandler(this.get_element(), "mousedown", this._mouseDownHandler);

      },

      // mousedown event handler

      _handleMouseDown: function(ev) {

        // DragDropManager need this

        window._event = ev;

        //set the style of the translucent element(s) dragged with the mouse moving

        this._visual = this.get_element().cloneNode(true);

        this._visual.style.opacity = "0.7";

        this._visual.style.filter =

          "progid:DXImageTransform.Microsoft.BasicImage(opacity=0.7)";

        this._visual.style.zIndex = 99999;

        this.get_element().parentNode.appendChild(this._visual);

        var location = Sys.UI.DomElement.getLocation(this.get_element());

        Sys.UI.DomElement.setLocation(this._visual, location.x, location.y);

        //notify the DragDropManager that the dragging has started

        Sys.Preview.UI.DragDropManager.startDragDrop(this, this._visual, null);

      },

      //destructor

      dispose: function() {

        if (this._mouseDownHandler)

          $removeHandler(this.get_element(), "mousedown", this._mouseDownHandler);

        this._mouseDownHandler = null;

        ShoppingCartNamespace.DraggableProductBehavior.callBaseMethod(this, 'dispose');

      }

    }

     

    Here, we give a typical MS AJAX styled JavaScript definition for a class prototype. Since there are detailed explanations accompanying the above code, we won't cover it any further, while there's one more word to be added -- note how we have implemented each method of the IDragSource interface and tell the DragDropManager to start the dragging operation.

    Finally, you have to register the DraggableProductBehavior's behavior into the MS AJAX client-side framework:

     

    ShoppingCartNamespace.DraggableProductBehavior.registerClass(

      "ShoppingCartNamespace.DraggableProductBehavior",

      Sys.UI.Behavior,

      Sys.Preview.UI.IDragSource

    );

     

    More ASP.NET Articles
    More By Xianzhong Zhu


       · Whats ironic is I just recently created a drag/drop DLL control or a customer and...
       · Hi, I'm very glad to hear that and would like to be notified. In fact, the current...
       · Hey guys, many tnx for the examples - beginners like me can get the right impuls to...
       · Thanks a lot for showing the path to ajax - specials.Latawiec
       · You're welcome. Remember that I'm just a newbie for MS AJAX (only for 6 months in...
     

    ASP.NET ARTICLES

    - ASP.NET DotNetNuke Installation with Visual ...
    - Using ASP.NET with a MySQL Database
    - Using ASP.NET with an MS Access Database
    - 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





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