Checking only one dock in a zone script

4 posts, 0 answers
  1. Alec
    Alec avatar
    43 posts
    Member since:
    Mar 2009

    Posted 09 Jul 2009 Link to this post

    I have got my script working to restrict only one dock in a zone.

    But the problem I am having is, it works only if I drag the dock below the current dock. Say there are two zones:

    Zone Destination
    Dock A

    Zone Origin
    Dock B

    I am moving Dock B to Zone Destination, when it is dropped, the script will check if Zone Destination has more than 1 dock, if so, remove old dock and replace with new dock. Old dock will get sent back to Zone Origin.

    It works fine, but only if I drag Dock B below Dock A. If I drag Dock B above Dock A, it will just append to the zone.

    What am I missing here?

    Here's the script:

     <script type="text/javascript">  
         function SetHandleDock(dock, args) {  
         var dockZoneID;  
         function checkMaximumDock(dock) {  
             var selectionZone = $find('<%= radDockZone.ClientID %>');  
             var newDockZoneID = dock.get_dockZoneID();  
             //if the dock is floated or dropped in the selection zone return    
             if (newDockZoneID == '' || selectionZone.get_clientID() == newDockZoneID) return;  
             if (dockZoneID != newDockZoneID) {  
                 var dockZone = $find(newDockZoneID);  
                 var docks = dockZone.get_docks();  
                 if (docks.length > 1) {  
                     var oldDock = docks[0];  
         function OnClientDragStart(dock) {  
             dockZoneID = dock.get_dockZoneID();  

    For dock B:

    radDock.OnClientDragEnd = "checkMaximumDock";  
    radDock.OnClientDragStart = "OnClientDragStart"
  2. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 14 Jul 2009 Link to this post

    If you dock a DockB above DockA -> dock[0] will be DockB. You can add a if else condition, e.g.

    var oldDock;
        oldDock = docks[1];
        oldDock = docks[0];
    Hope this helps.
  3. Alec
    Alec avatar
    43 posts
    Member since:
    Mar 2009

    Posted 29 Jul 2009 Link to this post

    Is there anyway I could do this check on server side ajax?
  4. Jim
    Jim avatar
    31 posts
    Member since:
    Jun 2009

    Posted 03 Aug 2009 Link to this post

    I think in general it is better to do this check on the client-side. It is a lot faster and you do not need a postback just to check if a condition is satisfied. However, if you need to do it you can handle the OnDockPositionChanged event and check the condition accordingly. The event handler should be similar to the following (note that this is not a complete code, just an example of how it can be done):

    protected void RadDock_DockPositionChanged(object sender, DockPositionChangedEventArgs e) 
        RadDock oldDock = new RadDock(); 
        RadDock dock = (RadDock)sender; 
            /// get the docking zone 
        RadDockZone dockingZone = (RadDockZone)FindControl(e.DockZoneID); 
            /// a way to do the check 
        if (dockingZone.Docks[0].ID == dock.ID) 
            oldDock = dockingZone.Docks[1]; 
            oldDock = dockingZone.Docks[0]; 

Back to Top