AJAX drag drop Challenge: new with profile support

I have written a proof of concept blog post about drag and drop with AJAX toolkit. In my second part I will take a look at the possibility's to store the new position. I earlier builds toolkit control supports direct storing in profile. That feature was dropped from toolkit.

My goal is to use DragPanelextender and read and write panel position from profile store. So I use a Panel, DragPanelExtender and a Label as dragobject.

<asp:Panel ID="dragPanel1" runat="server" BackColor="#00CC66" Height="83px"

Width="138px">

<asp:Label ID="dragLabel1" runat="server" Text="Dragme!"></asp:Label></asp:Panel>

<cc1:DragPanelExtender ID="Panel1_DragPanelExtender" runat="server"

DragHandleID="dragLabel1"

BehaviorID="dragPanelBehavior1"

Enabled="True" TargetControlID="dragPanel1">

</cc1:DragPanelExtender><br />

First we have to register a Event when dragpanel have a new location on page. We use propertchanged when  Page and AJAX Application is loaded. The Function Storeposition1 will handle the communication to AJAX profile service. The function setPostion is reading the values and setting the position on loading the page.

<script type="text/javascript" language="javascript">

window.onload = function() {

Sys.Application.add_load(ApplicationLoaded);

}

function ApplicationLoaded()

{

setPosition();

$find("dragPanelBehavior1").add_propertyChanged(storePosition1);

}

In web.config following entry's are necessary

First the typical format information of Profile Service

<profile enabled="true">

<properties>

<group name="dragdropprofile">

<add name="top" type="Integer" allowAnonymous="true"/>

<add name="left" type="Integer" allowAnonymous="true"/>

</group>

<add name="hannes" type="string"/>

</properties>

</profile>

Second the settings for the application bridge of profileService. The sample enable read and  write of top and left within dargdropprofile group.

<system.web.extensions>

<scripting>

<webServices>

<profileService enabled="true"

readAccessProperties="dragdropprofile.top, dragdropprofile.left"

writeAccessProperties="dragdropprofile.top, dragdropprofile.left"/>

</webServices>

</scripting>

</system.web.extensions>

Then we can go to the "dragged" event storePosition1 and look for the new location of the Panel. Use the behaviorID from DragPanelextender.

function storePosition1(sender, eventargs)

{

if(eventargs.get_propertyName() == 'location')

{

var dragPanel = $find('dragPanelBehavior1');

var loc = dragPanel.get_location() ;

Sys.Services.ProfileService.properties.dragdropprofile.top = loc.x;

Sys.Services.ProfileService.properties.dragdropprofile.left = loc.y;

Sys.Services.ProfileService.save(null, onSaveSuccess, onError,null);

}

}

Cause callbacks to server can take a while and should not stop UI from responding, profile save is done asynchronously. Events for succes and error are needed.

function onSaveSuccess(result, userContext, methodName)

{

alert("saved");

}

function onError()

{

alert("not saved");

}

When you have values in aspnetdb profile table you can restore the position of panel on page load.

function setPosition(){

var x=Sys.Services.ProfileService.properties.dragdropprofile.top;

var y=Sys.Services.ProfileService.properties.dragdropprofile.left;

var newLocation = new Sys.UI.Point(x,y);

$find('dragPanelBehavior1').set_location(newLocation)

}

At the end don't forget the Scriptmanager as first control on your page. I use a trick to load the profile property's without code by declaration.

<asp:ScriptManager ID="ScriptManager1" runat="server">

<ProfileService LoadProperties="dragdropprofile.top,dragdropprofile.left" />

</asp:ScriptManager>

that should it be! have fun and extend it with your ideas.

 

 

 

 

Published Sunday, January 27, 2008 11:46 PM by preishuber

Comments

# re: AJAX drag drop Challenge: new with profile support

Tuesday, January 29, 2008 11:05 AM by Christian

instead of window.onload = function() { ... }, you should use the pageLoad() function -- if your are unlucky, the Sys object is not available when window.onload occurs (window.onload happens when the HTML markup is fully loaded, but does not take external JavaScript files into account). Apart from that, very nice solution to a pending problem!

# re: AJAX drag drop Challenge: new with profile support

Tuesday, January 29, 2008 6:12 PM by Albert

Great information. I think that you have built a bridge here conecting many things that wouldn't be possible with the current extensions.

Could you please provide a link to download your existing code? I seem to be missing something, because I'm not getting it to function as stated above.

# re: AJAX drag drop Challenge: new with profile support

Wednesday, January 30, 2008 3:19 AM by Christian

Albert, you may need to be logged in in order to get the profile information saved (since the profile information by default is not accessible for anonymous users, unless you define it to do so)

# AJAX drag& drop challenge: science fiction with web.preview

Wednesday, January 30, 2008 2:56 PM by Hannes Preishuber

Drag and drop is one of the missing features from the final ASP.NET 2.0 AJAX Extensions 1.0 (what a name

# re: AJAX drag drop Challenge: new with profile support

Wednesday, March 05, 2008 3:29 PM by JSteve

Do you have a complete sample of this?

# re: AJAX drag drop Challenge: new with profile support

Thursday, May 01, 2008 1:52 PM by barkingmad

I have been trying to enable this with Dragpanel, and have never seen a good sample.  I have a lot of questions such as 1. How do you work with multiple panels (and update position in the Profile for the one you just dragged and dropped)?  2. How do you add target panels dynamically, and get that into the web.config properties the same way?  3. load the panel items you have added into the page on load or pre-render from the profile.  Any help would be a nice thing.

# re: AJAX drag drop Challenge: new with profile support

Saturday, July 12, 2008 9:02 AM by Rich

Hannes...

SEHR GUT!

Really brilliant, man.  I'm working on something like this and your code samples really helped.  If you don't want to use the Profile Service, you can always keep the location x and y values in javascript variables.  If they need to be posted back to the server, you could just put them in hidden fields, or manipulate other tag properties before posting back.

Viel mas danke!

Leave a Comment

(required) 
(required) 
(optional)
(required)