Wednesday, March 28, 2012

Programmatically add an Extender

I'm a huge newbie when it comes down to AJAX, ASP.NET and some more of the good stuff. I hope you don't mind me sticking around here ...

I've been playing around with de CustomDragDrop library provided by Omar Al Zabir. (http://www.codeproject.com/Ajax/MakingGoogleIG.asp)
I added some transparency while dragging and the ability to call a WebService or a WebMethod (on the Page) .

I've got a static example with a few div's which are draggable into other div's, registered as dropzone's.

Now, I want to makes this useable!
I've created a DataList and I want to programmaticaly add CustomFloatingBehavior to each DataListItem.
So in the event OnItemCreated, I make a new CustomFloatingBehaviorExtender and provide the necessary properties.
Finally I put my extender in the UpdatePanel and Update it.


There's just one thing I can't figure out ...
In the static version each draggable item has JS init handler looking like this:
Sys.Application.add_init(function() {
$create(CustomDragDrop.CustomFloatingBehavior, {"DragHandleID":"DragHandle","id":"WidgetFloatingBehavior"}, null, null, $get("DragItem"));
});


My dynamic version doesn't work yet, and it think the problem might be the above lines.
I should be able to programmatically add these for each DataListItem aswell.
Has anyone got anay suggestions?

Thanks in advance!

You'll find that dragdrop stuff is currently pretty poorly supported and you might be better off rolling your own.

Personally, I do drag-drop entirely on the client side (via $create(Sys.Preview.UI.FloatingBehavior...etc) calls), and I avoid UpdatePanels like the plague. As such, I'm not as clear on the UpdatePanel lifecycle and events as I should be to answer your question, but I suspect that the clientside init event is not fired by the updatepanel on partial postback. Consider isntead looking athttp://ajax.asp.net/docs/overview/PartialPageRenderingOverview.aspx and see if you can use that pagerequestmanage.add_pageLoaded() function (or one of the other member functions) to fire off a custom javascript that runs the $create() script on new draggable items.

No comments:

Post a Comment