Hello,
I'm creating a 'dashboard' on which the user can dynamically add dock controls. Each dock control contains a certain usercontrol.
Using the examples from the Telerik site, I already have created the dashboard and the functionality to add dock controls. But when I add a usercontrol, I get a null reference exception form the usercontrol. The usercontrol itself contains several buttons, which are null when I call dockLayout.Controls.Add(dock);
I'm not sure, but I think it has to do with the state of the page lifecycle.
The dock-widget example (http://www.telerik.com/help/aspnet-ajax/dock-widgets.html) I've using is probably the way to solve this problem, but the example doesn't explain how LoadControl() should be implemented. Is this the missing link? If so, can you give an example code, based on the provided example?
<
asp:Content
ID
=
"Content3"
ContentPlaceHolderID
=
"MainContent"
runat
=
"server"
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"ralpConfiguration"
>
</
telerik:RadAjaxLoadingPanel
>
<
telerik:RadAjaxPanel
runat
=
"server"
ID
=
"rapConfiguration"
LoadingPanelID
=
"ralpConfiguration"
>
<
telerik:RadWindow
ID
=
"modalPopup"
runat
=
"server"
Width
=
"360px"
Height
=
"360px"
Modal
=
"true"
>
<
ContentTemplate
>
<
asp:DropDownList
runat
=
"server"
ID
=
"ddlControls"
></
asp:DropDownList
>
<
asp:Button
runat
=
"server"
ID
=
"btnAddRadDock"
Text="Add" />
</
ContentTemplate
>
</
telerik:RadWindow
>
</
telerik:RadAjaxPanel
>
<
telerik:RadDockLayout
ID
=
"dockLayout"
runat
=
"server"
>
</
telerik:RadDockLayout
>
</
asp:Content
>
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
btnAddControl.Click += new EventHandler(btnAddControl_Click);
btnAddRadDock.Click += new EventHandler(btnAddRadDock_Click);
dockLayout.SaveDockLayout += new DockLayoutEventHandler(dockLayout_SaveDockLayout);
dockLayout.LoadDockLayout += new DockLayoutEventHandler(dockLayout_LoadDockLayout);
for (int i = 0; i < CurrentDockStates.Count; i++)
{
RadDock dock = new RadDock();
dock.ID = string.Format("RadDock{0}", i);
dock.ApplyState(CurrentDockStates[i]);
dockLayout.Controls.Add(dock);
}
}
protected void dockLayout_SaveDockLayout(object sender, DockLayoutEventArgs e)
{
CurrentDockStates = dockLayout.GetRegisteredDocksState();
}
protected void dockLayout_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
foreach (DockState state in CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
private void btnAddRadDock_Click(object sender, EventArgs e)
{
RadDock dock = CreateRadDock();
dock.Tag = ddlControls.SelectedValue;
LoadWidget(dock);
// the following line will trigger the page load of the user control, which in turn returns the null ref exception on a button within the user control
dockLayout.Controls.Add(dock);
}
private void LoadWidget(RadDock dock)
{
if (string.IsNullOrEmpty(dock.Tag))
return;
GisMapControl gisMapControl = new GisMapControl();
gisMapControl.IsFilterPanelVisible = false;
gisMapControl.LocationLimit = 100;
gisMapControl.FacilityLimit = 100;
dock.ContentContainer.Controls.Add(gisMapControl);
}
private RadDock CreateRadDock()
{
int docksCount = CurrentDockStates.Count;
RadDock dock = new RadDock();
dock.ID = string.Format("RadDock{0}", docksCount);
dock.Title = string.Format("Dock {0}", docksCount);
dock.Text = string.Format("Added at {0}", DateTime.Now);
dock.UniqueName = Guid.NewGuid().ToString();
dock.Width = Unit.Pixel(300);
return dock;
}