I am dynamically creating docks when a user clicks a button, inside the dock will be various controls depending on what "page widget" the user has selected from the dropdown list.
I have started off with the simplest "page widget", a RadEditor and a Textbox.
I can persist any data entered into the controls by saving it to a session and re-populate the various controls, however I need to be able to move the docks around so that the order of the "page widgets" can be changed easily but I've lost this functionality, I cannot move, collapse or remove them.
I have simplified the code down to the basics to make it easier to read.
Any ideas? Thanks
(I don't care about the docks open/close state, collapsing will be removed)
ASPX
VB
I have started off with the simplest "page widget", a RadEditor and a Textbox.
I can persist any data entered into the controls by saving it to a session and re-populate the various controls, however I need to be able to move the docks around so that the order of the "page widgets" can be changed easily but I've lost this functionality, I cannot move, collapse or remove them.
I have simplified the code down to the basics to make it easier to read.
Any ideas? Thanks
(I don't care about the docks open/close state, collapsing will be removed)
ASPX
<asp:Button ID="btnAdd" runat="server" Text="Add a widget" /><br /><br /><telerik:RadDockLayout ID="rdDockLayout" runat="server"> <telerik:RadDockZone ID="rdDockZone" runat="server" Width="700px"> </telerik:RadDockZone></telerik:RadDockLayout>VB
Imports Telerik.Web.UIPartial Class Admin_DockTest2 Inherits System.Web.UI.Page Dim DockStore As New List(Of DockSaved) ''' <summary> ''' Container to hold a saved dock so it can be brought back in to dock zone on postback etc. ''' </summary> Private Structure DockSaved Property Key As Integer Property WidgetObject As PageWidgets Property dID As String Public Sub New(WidgetTypeID As Integer, Widget As PageWidgets, dockID As String) Key = WidgetTypeID WidgetObject = Widget dID = dockID End Sub End Structure Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init If Not Session("Widgets") Is Nothing Then DockStore = CType(Session("Widgets"), List(Of DockSaved)) End If End Sub Protected Sub btnAdd_Click(sender As Object, e As System.EventArgs) Handles btnAdd.Click AddWidget() End Sub Private Sub AddWidget() CreateDock(1) 'type 1 End Sub Private Sub CreateDock(WidgetType As Integer) Dim randID As String = Guid.NewGuid().ToString.Replace("-", "a") Dim dock As New RadDock dock.ID = "dk" + WidgetType.ToString() + "-" + randID dock.Title = "dk" + WidgetType.ToString() + DateTime.Now.ToShortTimeString dock.ClientIDMode = UI.ClientIDMode.Static dock.Commands.Add(New DockExpandCollapseCommand()) dock.Commands.Add(New DockCloseCommand()) dock.AutoPostBack = True dock.EnableDrag = True Dim rdTextboxID = "tb" + randID Dim rdTextbox As RadTextBox = GetRadTextbox(rdTextboxID) rdTextbox.Text = "help!" Dim rdEditorID As String = "rdEditor" + randID Dim rdEditor As RadEditor = GetRadEditor(rdEditorID) dock.ContentContainer.Controls.Add(rdTextbox) dock.ContentContainer.Controls.Add(rdEditor) rdDockLayout.Controls.Add(dock) dock.Dock(rdDockZone) End Sub Protected Sub rdDockLayout_SaveDockLayout(sender As Object, e As Telerik.Web.UI.DockLayoutEventArgs) Handles rdDockLayout.SaveDockLayout If rdDockZone.Docks.Count > 0 Then 'Clear current entries to avoid saving duplicates DockStore.Clear() For Each d In rdDockZone.Docks Dim dID As String = d.ID Dim randID As String = d.ID.Substring(4) Dim WidgetTypeID As Integer = 1 Select Case WidgetTypeID Case 1 '>>>>> Widget Type: WidgetHTML Dim tbID As String = "tb" + randID Dim rdTextbox As RadTextBox = CType(d.ContentContainer.FindControl(tbID), RadTextBox) Dim rdEditorID As String = "rdEditor" + randID Dim rdEditor As RadEditor = CType(d.ContentContainer.FindControl(rdEditorID), RadEditor) Dim widget As New WidgetHTML 'Populate a widget widget.SchemeID = 2 widget.Title = rdTextbox.Text widget.HTML = rdEditor.Content widget.Visible = True 'save widget Dim ds As New DockSaved(1, widget, dID) DockStore.Add(ds) Case 2 '>>>>> Widget Type: ....... End Select Next End If Session("Widgets") = DockStore End Sub Protected Sub rdDockLayout_LoadDockLayout(sender As Object, e As Telerik.Web.UI.DockLayoutEventArgs) Handles rdDockLayout.LoadDockLayout If DockStore.Count > 0 Then For Each w In DockStore Dim widgy As WidgetHTML = CType(w.WidgetObject, WidgetHTML) Dim dock As New RadDock dock.ID = w.dID dock.Title = "dk - returned" dock.ClientIDMode = UI.ClientIDMode.Static dock.Commands.Add(New DockExpandCollapseCommand()) dock.Commands.Add(New DockCloseCommand()) dock.AutoPostBack = True dock.EnableDrag = True Dim randID As String = w.dID.Substring(4) 'if type 1 Dim rdEditorID As String = "rdEditor" + randID Dim rdTextboxID = "tb" + randID Dim rdTextbox As RadTextBox = GetRadTextbox(rdTextboxID) rdTextbox.Text = widgy.Title Dim rdEditor As RadEditor = GetRadEditor(rdEditorID) rdEditor.Content = widgy.HTML dock.ContentContainer.Controls.Add(rdTextbox) dock.ContentContainer.Controls.Add(rdEditor) rdDockLayout.Controls.Add(dock) dock.Dock(rdDockZone) Next End If End Sub ''' <summary> ''' HTML components to build WebWidgets. ''' </summary> ''' <param name="WidgetName">Desired ID of the control.</param> ''' <returns>Returns the control requested with the correct ID.</returns>#Region "Widgets" Private Function GetRadTextbox(WidgetName As String) As RadTextBox Dim rdTextbox As New RadTextBox rdTextbox.ID = WidgetName rdTextbox.ClientIDMode = UI.ClientIDMode.Static rdTextbox.Skin = "Windows7" Return rdTextbox End Function Private Function GetRadEditor(WidgetName As String) As RadEditor Dim rdEditor As New RadEditor rdEditor.ID = WidgetName rdEditor.ClientIDMode = UI.ClientIDMode.Static rdEditor.Skin = "Windows7" Return rdEditor End Function#End RegionEnd Class