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

Dynamically Created Docks not Saving Position on First Postback

5 Answers 113 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Brett Mckee
Top achievements
Rank 1
Brett Mckee asked on 02 Feb 2010, 04:01 PM
I am creating new docks dynamically from a button click event and saving state to a database.  Everything seems to be working flawlessly with one exception.  P  To create the controls on the button click I use the following events and code in the order they appear(please forgive the state of the code as right now, I am merely concerned with getting this working.):

private void LoadWidget(int widgetID) 
        { 
            NCSBlackRadDock dock = CreateDock(widgetID); 
            LoadWidget(dock); 
            this.RadDockZone_Center.Controls.Add(dock); 
        } 
 
private NCSBlackRadDock CreateDock(int widgetID) 
        { 
    //Pulls properties for the dock to be loaded from database.
            SqlParameter[] param = { new SqlParameter("@WidgetID", widgetID) }; 
            DataSet ds = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["NCSBlackDashboardConnectionString"].ConnectionString, CommandType.StoredProcedure, "dbo.GetWidgetInfo", param); 
 
            NCSBlackRadDock dock = new NCSBlackRadDock(); 
            dock.ID = Guid.NewGuid().ToString(); 
            dock.Tag = ds.Tables[0].Rows[0][1].ToString(); 
            dock.Title = "Test"
            dockdock.Text = dock.ID.ToString(); 
            dockdock.UniqueName = dock.ID; 
            dock.widgetIcon.ImageUrl = ds.Tables[0].Rows[0][2].ToString(); 
            dock.WidgetTitle.Text = ds.Tables[0].Rows[0][0].ToString(); 
            dock.AutoPostBack = true
 
            return dock; 
        } 
 
private void LoadWidget(NCSBlackRadDock dock) 
        { 
            if (string.IsNullOrEmpty(dock.Tag)) 
            { return; } 
 
            try 
            { 
                Control widget = LoadControl(dock.Tag); 
                //dock.widgetPanel.Controls.Add(widget);   
                dock.ContentContainer.Controls.Add(widget); 
            } 
            catch { } 
        } 

You'll notice that we are using an extended version of the RadDock, but merely to expose a couple new properties.  Very surface level stuff.  So, on the click the new dock is loaded to the center dockzone and everything looks great.  I can reproduce the problem from this point.  With any newly added widget if the first action is a position change of the newly added dock the dock can be dragged to any available dockzone on the client side and stick there, but upon postback it will snap back to its original position.  During any subsequent postbacks after the initial, everything works as desired.

Additionally, by following the event flow I can see that on the first postback the call to "((RadDockLayout)sender).GetRegisteredDocksState()" during the "SaveDockLayout" event shows that the DockState of the dock in question is not set to the appropriate DockZoneID, HOWEVER, during all subsequent postbacks the DockZoneID is set appropriately every time its changed.

So, I guess my question is, why wouldnt the RegisteredDockState of newly added docks get updated on a position change postback until after 1 postback has occured?  It seems like I might be missing something while loading my controls on Page_Init?  Here is the code for that method:

protected void Page_Init(object sender, EventArgs e) 
        { 
            for (int i = 0; i < CurrentDockStates.Count; i++) 
            { 
                NCSBlackRadDock dock = new NCSBlackRadDock(); 
                DockState ds = CurrentDockStates[i]; 
                dock.ApplyState(CurrentDockStates[i]); 
                CreateSaveStateTrigger(dock); 
                LoadWidget(dock); 
 
                RadDockLayout_Content.Controls.Add(dock); 
 
            } 
             
        } 

All the CreateSaveStateTrigger method does at this point is set the docks AutoPostBack and CommandAutoPostBack properties to true.

I've tried my best to explain this coherently, any thoughts?

5 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 05 Feb 2010, 11:44 AM
Hello Brett,

With this information and source code provided I think the problem might be caused by the following reasons:
  • Make sure that you are handling the LoadDockLayout event, since in this event you are populating the event args with the state information and the RadDockLayout control will automatically move the docks according that information.
  • I noticed that you are creating the ID of the dock dynamically with the following line dock.ID = Guid.NewGuid().ToString();. The Guid.NewGuid() method does not always return a valid string for a control's ID. It can start with a numeric character and contains '-'. Please replace this code line with the following: dock.ID= string.Format("RadDock{0}", Guid.NewGuid().ToString().Replace('-', 'a'));
  • If your layout (i.e. the DockLayout and zones) is placed within a UserControl then this UserControl should be loaded in the Page_Init so the docks can be placed in the right zone and position.

If the problem still persists please send us a fully working project that demonstrates the problem and we will do our best to provide a solution. You need to open a support ticket to attach files.


Kind regards,
Pero
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Brett Mckee
Top achievements
Rank 1
answered on 05 Feb 2010, 05:23 PM
I've created a support ticket for this issue with a simple project that demonstrates the issue.  Ticket number 279572
0
Pero
Telerik team
answered on 08 Feb 2010, 11:49 AM
Hi Brett,

Thank you for the sample project. I reproduced the problem immediately. It seems to be caused by the fact that you are never setting IDs to the docks that are recreated in the Page_Init.

protected void Page_Init(object sender, EventArgs e)
{
    if (CurrentDockStates != null)
    {
        for (int i = 0; i < CurrentDockStates.Count; i++)
        {
            RadDock dock = new RadDock();
            DockState ds = CurrentDockStates[i];
            dock.ApplyState(CurrentDockStates[i]);
            dock.AutoPostBack = true;
            LoadWidget(dock);
            RadDockLayout_Content.Controls.Add(dock);
        }
    }
}

The ApplyState(DockState) does not set an ID to the recreated RadDock, it only sets the UniqueName.

This is the modified source code of the Page_Init event handler:
protected void Page_Init(object sender, EventArgs e)
{
    if (CurrentDockStates != null)
    {
        for (int i = 0; i < CurrentDockStates.Count; i++)
        {
            RadDock dock = new RadDock();
            DockState ds = CurrentDockStates[i];
 
            //Set an ID
            dock.ID = ds.UniqueName;
 
            dock.ApplyState(CurrentDockStates[i]);
            dock.AutoPostBack = true;
            LoadWidget(dock);
            RadDockLayout_Content.Controls.Add(dock);
        }
    }
}


Kind regards,
Pero
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Frank
Top achievements
Rank 1
answered on 23 Feb 2012, 11:13 PM
I am having the same issue with a dynamically loaded usercontrol that contains a raddocklayout. How would this work in a page that has autoeventwireup set to false?
0
Slav
Telerik team
answered on 28 Feb 2012, 12:23 PM
Hello Frank,

The AutoEventWireup="false" setting should not affect the RadDock controls' behavior, you just need to ensure that the page lifecycle event handlers are attached.  Are you creating the RadDock controls programmatically? On which server-side event of your page is the user control with the RadDocks added? I would suggest checking the listed scenarios, which Pero provided in one of his previous posts and especially the following:
If your layout (i.e. the DockLayout and zones) is placed within a UserControl then this UserControl should be loaded in the Page_Init so the docks can be placed in the right zone and position.

If you are still having difficulties after examining the information above, please open a support ticket and isolate your problem in a simple, fully runnable page so that we can inspect it locally and provide further assistance.

Greetings,
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
Brett Mckee
Top achievements
Rank 1
Answers by
Pero
Telerik team
Brett Mckee
Top achievements
Rank 1
Frank
Top achievements
Rank 1
Slav
Telerik team
Share this question
or