i am dynamically creating RadDocks from an Array for the 1st time and then using the loaded docks i want to save them in the database for per user basis.
i also have a update panel for the "DockPositionChanged" event, however this is giving the following error.
A control with ID 'RadDockf49937fe-b13d-4730-b098-d252bb02fc45' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
please advise..
here is the source code
i also have a update panel for the "DockPositionChanged" event, however this is giving the following error.
A control with ID 'RadDockf49937fe-b13d-4730-b098-d252bb02fc45' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
please advise..
here is the source code
| <telerik:raddocklayout runat="server" id="RadDockLayout1" |
| onsavedocklayout="RadDockLayout1_SaveDockLayout" |
| onloaddocklayout="RadDockLayout1_LoadDockLayout"> |
| <table cellspacing="5" cellpadding="5" border="0" width="690"> |
| <tr> |
| <td> |
| <telerik:RadDockZone ID="RadDockZone1" runat="server" Width="330px" MinHeight="243px" MinWidth="330px"> |
| </telerik:RadDockZone> |
| </td> |
| <td> |
| <telerik:RadDockZone ID="RadDockZone2" runat="server" Width="330px" MinHeight="243px" MinWidth="330px"> |
| </telerik:RadDockZone> |
| </td> |
| </tr> |
| <tr> |
| <td colspan="2"> |
| <div style="display:none"> |
| Hidden UpdatePanel, which is used to receive the new dock controls. |
| We will move them with script to the desired initial dock zone. |
| <asp:updatepanel runat="server" id="UpdatePanel1"> |
| </asp:updatepanel> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </telerik:raddocklayout> |
| using System; |
| using System.Collections; |
| using System.Collections.Generic; |
| using System.ComponentModel; |
| using System.Data; |
| using System.Drawing; |
| using System.Web; |
| using System.Web.SessionState; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.HtmlControls; |
| using Telerik.Web.UI; |
| using System.Data.SqlClient; |
| using System.Configuration; |
| using System.Text; |
| public partial class Portal : System.Web.UI.Page |
| { |
| private SqlConnection _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DockConnectionString"].ConnectionString); |
| private int _count = 0; |
| bool LoadDefaults = true; |
| protected void Page_Init(object sender, EventArgs e) |
| { |
| LoadDefaults=true; |
| if (LoadDefaults) |
| LoadDefaultsFromSharePoint(); |
| else |
| LoadFromDatabase(); |
| } |
| private void LoadDefaultsFromSharePoint() |
| { |
| string[] WidgetTitles = { "ECAMPAIGNS","NEWS","MY LISTINGS","MY CALENDAR"}; |
| string[] WidgetControls = { "HP_eCampaign.ascx", "HP_News.ascx", "HP_Listings.ascx", "HP_Calendar.ascx"}; |
| //Recreate the docks in order to ensure their proper operation |
| bool isZoneOne=true; |
| int i = 0; |
| foreach (string widget in WidgetTitles) |
| { |
| RadDock dock = CreateRadDock(widget, WidgetControls[i]); |
| //We will just add the RadDock control to the RadDockLayout. |
| // You could use any other control for that purpose, just ensure |
| // that it is inside the RadDockLayout control. |
| // The RadDockLayout control will automatically move the RadDock |
| // controls to their corresponding zone in the LoadDockLayout |
| // event (see below). |
| if (isZoneOne) |
| { |
| isZoneOne=false; |
| RadDockZone1.Docks.Add(dock); |
| } |
| else |
| { |
| isZoneOne=true; |
| RadDockZone2.Docks.Add(dock); |
| } |
| //We want to save the dock state every time a dock is moved. |
| CreateSaveStateTrigger(dock); |
| i++; |
| } |
| } |
| private void LoadFromDatabase() |
| { |
| string dockState = ""; |
| try |
| { |
| _conn.Open(); |
| SqlCommand command = new SqlCommand("select State from States where id=1", _conn); |
| dockState = command.ExecuteScalar().ToString(); |
| _conn.Close(); |
| } |
| catch |
| { |
| } |
| string[] currentDockStates = dockState.Split('|'); |
| _count = currentDockStates.Length; |
| //Recreate the docks in order to ensure their proper operation |
| for (int i = 0; i < _count; i++) |
| { |
| if (currentDockStates[i].Trim() != string.Empty) |
| { |
| RadDock dock = CreateRadDockFromState(currentDockStates[i]); |
| //We will just add the RadDock control to the RadDockLayout. |
| // You could use any other control for that purpose, just ensure |
| // that it is inside the RadDockLayout control. |
| // The RadDockLayout control will automatically move the RadDock |
| // controls to their corresponding zone in the LoadDockLayout |
| // event (see below). |
| RadDockLayout1.Controls.Add(dock); |
| //We want to save the dock state every time a dock is moved. |
| CreateSaveStateTrigger(dock); |
| } |
| } |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| } |
| private RadDock CreateRadDockFromState(string stringState) |
| { |
| System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); |
| DockState state = serializer.Deserialize<DockState>(stringState); |
| RadDock dock = new RadDock(); |
| dock.ID = string.Format("RadDock{0}", state.UniqueName); |
| dock.ApplyState(state); |
| return dock; |
| } |
| private RadDock CreateRadDock(string WidgetTitle, string WidgetControlName) |
| { |
| RadDock dock = new RadDock(); |
| dock.UniqueName = Guid.NewGuid().ToString(); |
| dock.ID = string.Format("RadDock{0}", dock.UniqueName); |
| dock.Title = WidgetTitle; |
| dock.Width = Unit.Pixel(330); |
| dock.Height = Unit.Pixel(243); |
| try |
| { |
| Control widget = LoadControl(WidgetControlName); |
| } |
| catch (Exception ex) |
| { |
| dock.Text = string.Format("Error in Widget: {0}", ex.Message); |
| } |
| //dock.DefaultCommands= |
| return dock; |
| } |
| private void CreateSaveStateTrigger(RadDock dock) |
| { |
| //Ensure that the RadDock control will initiate postback |
| // when its position changes on the client or any of the commands is clicked. |
| //Using the trigger we will "ajaxify" that postback. |
| dock.AutoPostBack = true; |
| dock.CommandsAutoPostBack = true; |
| AsyncPostBackTrigger saveStateTrigger = new AsyncPostBackTrigger(); |
| saveStateTrigger.ControlID = dock.ID; |
| saveStateTrigger.EventName = "DockPositionChanged"; |
| UpdatePanel1.Triggers.Add(saveStateTrigger); |
| } |
| protected void RadDockLayout1_SaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e) |
| { |
| string dockState; |
| System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); |
| List<DockState> stateList = RadDockLayout1.GetRegisteredDocksState(); |
| StringBuilder serializedList = new StringBuilder(); |
| int i = 0; |
| while (i < stateList.Count) |
| { |
| serializedList.Append(serializer.Serialize(stateList[i])); |
| serializedList.Append("|"); |
| i++; |
| } |
| dockState = serializedList.ToString(); |
| if (dockState.Trim() != String.Empty) |
| { |
| try |
| { |
| _conn.Open(); |
| SqlCommand command = new SqlCommand(String.Format("update States set State='{0}' where id=1", dockState), _conn); |
| command.ExecuteNonQuery(); |
| _conn.Close(); |
| } |
| catch |
| { |
| } |
| } |
| //Save the dockState string into DB |
| } |
| protected void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e) |
| { |
| if (!LoadDefaults) // Perform this task only when not loading defaults,I.E when reading from database |
| { |
| System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); |
| //Get saved state string from the database - set it to dockState variable for example |
| string dockState = ""; |
| try |
| { |
| _conn.Open(); |
| SqlCommand command = new SqlCommand("select State from States where id=1", _conn); |
| dockState = command.ExecuteScalar().ToString(); |
| _conn.Close(); |
| } |
| catch |
| { |
| } |
| string[] currentDockStates = dockState.Split('|'); |
| foreach (string stringState in currentDockStates) |
| { |
| if (stringState.Trim() != string.Empty) |
| { |
| DockState state = serializer.Deserialize<DockState>(stringState); |
| e.Positions[state.UniqueName] = state.DockZoneID; |
| e.Indices[state.UniqueName] = state.Index; |
| } |
| } |
| } |
| } |
| } |