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?