This is a migrated thread and some comments may be shown as answers.

How to add dock dynamically at the top of zone

4 Answers 62 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 09 Jun 2008, 02:30 PM
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,

4 Answers, 1 is accepted

Sort by
0
Accepted
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 10 Jun 2008, 02:00 PM
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);



0
Scott
Top achievements
Rank 1
answered on 11 Jun 2008, 09:03 PM

it does the trick. thank you !!!

0
Martin Roussel
Top achievements
Rank 1
answered on 19 Nov 2012, 01:17 PM
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
0
Slav
Telerik team
answered on 22 Nov 2012, 12:20 PM
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.
Tags
Dock
Asked by
Scott
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Martin Roussel
Top achievements
Rank 1
Slav
Telerik team
Share this question
or