How to add dock dynamically at the top of zone

5 posts, 1 answers
  1. Scott
    Scott avatar
    4 posts
    Member since:
    Dec 2006

    Posted 09 Jun 2008 Link to this post

    I am using the following sample codes to add a new dock to middle zone successfully. The issue is everytime the new dock is always added at the buttom of the middle zone.

    Is there a way to add the new dock at the top of middle zone?

    ------------------
    ScriptManager.RegisterStartupScript(
                        theDock,
                        this.GetType(),
                        "AddDock",
                        string.Format(@"function _addDock() {{
                            Sys.Application.remove_load(_addDock);
                            $find('{1}').dock($find('{0}'));
                            $find('{0}').doPostBack('DockPositionChanged');
                            }};
                            Sys.Application.add_load(_addDock);",
                            theDock.ClientID,
                            this.MiddleCustomZone.ClientID),
                            true);
                    
                    CreateSaveStateTrigger(theDock);
    -----------------

    thanks,
  2. Answer
    Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 10 Jun 2008 Link to this post

    You can use dock method with additional parameter which is responsible for the new RadDock position, e.g.
    $find("RadDockZone1").dock($find("RadDock2"),0);
    The RadDock2 will be docked at the first place in RadDockZone1.

    So you should change:
    $find('{1}').dock($find('{0}'));
    With this one:
    $find('{1}').dock($find('{0}'),0);



  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Scott
    Scott avatar
    4 posts
    Member since:
    Dec 2006

    Posted 11 Jun 2008 Link to this post

    it does the trick. thank you !!!

  5. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 19 Nov 2012 Link to this post

    Hi,
    the solution provided works when I add only one dock to my dockzone. However, in my app, the user can select multiple docks to be added at once (selection from radcombobox with checkboxes). When doing so, the first dock selected goes on top but the rest going below the already existing docks.

    Ex: 
    0 - new dock 1
    1 - old dock
    2- new dock 2
    3- new dock 3

    here is my code:
    for (int i = 0; i <= combo.Items.Count - 1; i++)
                {
                    if (combo.Items[i].Checked)
                    {
                        combo.Items[i].Checked = false;
                        RadDock dock = CreateRadDock();
     
                        //adding the dock to the docklayout and then docking it to the zone to avoid ViewState issues on subsequent postback
                        RadDockLayout1.Controls.Add(dock);
                         
                        dock.Dock(RadDockZone1);
     
                            ScriptManager.RegisterStartupScript(
                            dock,
                            this.GetType(),
                            "AddDock",
                            string.Format(@"function _addDock() {{
                            Sys.Application.remove_load(_addDock);
                            $find('{1}').dock($find('{0}'),0);
                            }};
                            Sys.Application.add_load(_addDock);",
                                dock.ClientID,
                                this.RadDockZone1.ClientID),
                                true);
     
                        CreateSaveStateTrigger(dock);
     
                    }
                }

    Im also not sure if registering scripts in a loop like that is a good practice. Isnt there a better way, especially server-side? Seems like we cant specifiy position in "dock.Dock(RadDockZone1);"

    TIA
  6. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 22 Nov 2012 Link to this post

    Hello Martin,

    Please note that every time you register a client-side script you use the same name for the function. As a result the last function definition of _addDock overrides the previous ones and only the first dock's index is changed. My suggestion is to dock all RadDock controls in a single function and register it once as shown in the following code sample:
    RadDock dock = new RadDock();
    dock.ID = "RadDock1";
    dock.Title = "RadDock1";
    RadDockLayout1.Controls.Add(dock);
     
    RadDock dock2 = new RadDock();
    dock2.ID = "RadDock2";
    dock2.Title = "RadDock2";
    RadDockLayout1.Controls.Add(dock2);
     
    RadDock dock3 = new RadDock();
    dock3.ID = "RadDock3";
    dock3.Title = "RadDock3";
    RadDockLayout1.Controls.Add(dock3);
     
    string scriptAddDock1 = "$find('" + this.RadDockZone1.ClientID + "').dock($find('" + dock.ClientID + "'),0);";
    string scriptAddDock2 = "$find('" + this.RadDockZone1.ClientID + "').dock($find('" + dock2.ClientID + "'),0);";
    string scriptAddDock3 = "$find('" + this.RadDockZone1.ClientID + "').dock($find('" + dock3.ClientID + "'),0);";
    string fullScript1 = "function _addDocks() {Sys.Application.remove_load(_addDocks); " + scriptAddDock3 + scriptAddDock2 + scriptAddDock1 + "}; Sys.Application.add_load(_addDocks);";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "positionDocks", fullScript1, true);


    All the best,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017