Delving Deeper into Drag and Drop Programming in Microsoft ASP.NET AJAX - Dealing with the order via Web Service
(Page 5 of 5 )
When the customer finally clicks the Order button near the shopping cart, he can see a message showing the data result he cares about within a red rectangle below the shopping cart area. This is accomplished by asynchronously posting back the current information about the pets to buy that needs to be processed to the server side. The following code corresponds to the click event handler of the Order button:
function btnOrder_onclick() {
//get behavior ShoppingCartBehavior attached to the shopping cart
var shoppingCartBehavior = Sys.UI.Behavior.getBehaviorByName(
$get("shoppingCart"),
"myShoppingCartBehavior"
);
//Get the Id and quantity of each pet in the shopping cart
var productsToBeOrdered =
shoppingCartBehavior.getProductsToBeOrdered();
//Call Web Service to deal with the order
ShoppingService.Order(productsToBeOrdered, onOrdered);
}
As is seen from above, we first use the Sys.UI.Behavior.getBehaviorByName() method to get the behavior-ShoppingCartBehavior that is attached to the shopping cart, then obtain the Id and quantity of each pet in the shopping cart, and finally post this information back to the Web Service to be processed.
Here, still for demonstration purposes, in the call back function productsToBeOrdered() we've used an HTML element div to display the response from the server to the user:
function onOrdered(result) {
OutputMsg.innerHTML=result;}
So much for this sample; you can press F5 and give it a test! I bet you will be attracted by the friendly interface.
Final Thoughts
In this article, we first briefly compared most of the drag and drop solutions supplied by the MS AJAX framework, then summed up the inner workings of the drag and drop mechanism on the client side. After that, we focused on the client-side interfaces IDragSouce and IDropTarget, and also the DragDropManager and gave an integrated and complex example. Finally, we should notice that the MS AJAX framework has been undergoing rapid and great changes day after day; thus, only by keeping up with the changes can we web developers create the most professional, attractive and cross-browser compatible web applications.
| 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. |