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

Problem with dynamically created RadDock controls

1 Answer 84 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Nagasree
Top achievements
Rank 1
Nagasree asked on 08 May 2013, 07:48 PM
Hi,

I am creating raddock controls dynamically based on the data from the database. Everything is working except the state is not changing on the initial postback. It works perfectly afterwards. Am I missing anything? 

I am saving the state to the database after every change. Below is the code snippet of the page and the user control. Please take a look and let me know if I am missing anything. 

TabDash.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Desktop/MasterPages/Dasboard.master" AutoEventWireup="true" CodeFile="TabDash.aspx.cs" Inherits="Desktop_TabDash" %><br><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><br><%@ Register TagPrefix="azimaDLI" TagName="Tab1" Src="~/Desktop/Controls/Tab1.ascx" %><br><br><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"><br></asp:Content><br><asp:Content ID="Content2" ContentPlaceHolderID="mainContent" Runat="Server"><br>    <br>    <script type="text/javascript" src="FusionCharts/FusionCharts.js"></script><br>    <script type="text/javascript" src="Scripts/contextHelp.js?"></script><br><br>    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /><br>    <br>    <div class="exampleWrapper"><br>        <telerik:RadTabStrip runat="server" ID="RadTabStrip1" Orientation="HorizontalTop"<br>            SelectedIndex="0" MultiPageID="RadMultiPage1" ><br>            <Tabs><br>                <telerik:RadTab Text="Tab 1"></telerik:RadTab><br>                <telerik:RadTab Text="Tab 2"></telerik:RadTab><br>            </Tabs><br>        </telerik:RadTabStrip><br>        <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0" Height="218px"<br>            Width="396px" CssClass="multiPage" OnPageViewCreated="RadMultiPage1_PageViewCreated" >            <br>        </telerik:RadMultiPage><br>    </div><br></asp:Content>

TabDash.aspx.cs
using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Web;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using AzimaDLI.Users;<br>using AzimaDLI;<br>using Telerik.Web.UI;<br><br>public partial class Desktop_TabDash : BasePage<br>{<br>    public int selectedPlantId = 0;<br>    private string connString = string.Empty;<br>    private int histPlantId = 0;<br>    private User thisUser = null;<br><br>    protected void Page_Init(object sender, EventArgs e)<br>    {<br>        if (Session != null)<br>        {<br>            connString = Session["ConnString"].ToString();<br>            thisUser = ((User)Session["User"]);<br>        }<br><br>        if (!Page.IsPostBack)<br>        {<br>            LoadPlantsDDL();<br>            AddPageView("Tab1");<br>            AddPageView("Tab2");<br>        }<br>    }<br><br>    private void AddPageView(string tabname)<br>    {<br>        RadPageView pageView = new RadPageView();<br>        pageView.ID = tabname;<br>        RadMultiPage1.PageViews.Add(pageView);<br>    }<br><br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br><br>    }<br>    protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)<br>    {<br>        string userControlName = string.Format("~/Desktop/Controls/{0}.ascx", e.PageView.ID);<br>        Control userCtrl = Page.LoadControl(userControlName);<br>        userCtrl.ID = e.PageView.ID + "_userCtrl";<br>        e.PageView.Controls.Add(userCtrl);<br>    }<br><br>}<br>

Tab1.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Tab1.ascx.cs" Inherits="Desktop_Controls_Tab1" %><br><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><br><br><telerik:RadDockLayout ID="RadDockLayout1" runat="server" Skin="Metro" <br>     OnSaveDockLayout="RadDockLayout1_SaveDockLayout" ><br>    <table><br>        <tr><br>            <td style="vertical-align: top">                <br>                <telerik:RadDockZone ID="RadDockZone0" runat="server" Orientation="Vertical" Width="350px" <br>                    MinHeight="400px" Style="float: left; margin-right: 20px;"><br>                    <br>                </telerik:RadDockZone><br>            </td><br>            <td style="vertical-align: top"><br>                <telerik:RadDockZone ID="RadDockZone1" runat="server" Orientation="Vertical" Width="350px"<br>                    MinHeight="400px" Style="float: left; margin-right: 20px;"><br>                    <br>                </telerik:RadDockZone><br>            </td><br>            <td style="vertical-align: top"><br>                <telerik:RadDockZone ID="RadDockZone2" runat="server" Orientation="Vertical" Width="350px"<br>                    MinHeight="400px"><br>                    <br>                </telerik:RadDockZone><br>            </td><br>        </tr><br>    </table><br></telerik:RadDockLayout>

Tab1.ascx.cs
using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Web;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using AzimaDLI;<br>using AzimaDLI.Users;<br>using Telerik.Web.UI;<br>using System.Text;<br><br>public partial class Desktop_Controls_Tab1 : BaseControl<br>{<br>    public int selectedPlantId = 0;<br>    private string connString = string.Empty;<br>    User thisUser = null;<br><br>    //Store the info about the added docks in the session.<br>    private List<DockState> CurrentDockStates<br>    {<br>        get<br>        {<br>            List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStates"];<br>            if (Object.Equals(_currentDockStates, null))<br>            {<br>                _currentDockStates = new List<DockState>();<br>                Session["CurrentDockStates"] = _currentDockStates;<br>            }<br>            return _currentDockStates;<br>        }<br>        set<br>        {<br>            Session["CurrentDockStates"] = value;<br>        }<br>    }<br><br>    protected void Page_Init(object sender, EventArgs e)<br>    {     <br>        if (Session != null)<br>        {<br>            connString = Session["ConnString"].ToString();<br>            thisUser = ((User)Session["User"]);<br>        }<br><br><br>        if (Page.IsPostBack)<br>        {<br>            //UpdateLayoutState();<br>            //Recreate the docks in order to ensure their proper operation<br>            for (int i = 0; i < CurrentDockStates.Count; i++)<br>            {<br><br>                RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);<br>                //We will just add the RadDock control to the RadDockLayout.<br>                // You could use any other control for that purpose, just ensure<br>                // that it is inside the RadDockLayout control.<br>                // The RadDockLayout control will automatically move the RadDock<br>                // controls to their corresponding zone in the LoadDockLayout<br>                // event (see below).<br>                RadDockLayout1.Controls.Add(dock);<br>                //We want to save the dock state every time a dock is moved.<br>                CreateSaveStateTrigger(dock);<br>                //Load the selected widget<br>                if (string.IsNullOrEmpty(dock.Tag) || dock.Closed)<br>                {<br>                    return;<br>                }<br>                Control widget = LoadControl(dock.Tag);<br>                dock.ContentContainer.Controls.Add(widget);<br><br>                if (CurrentDockStates[i].Closed == true)<br>                {<br>                    dock.Visible = false;<br>                }<br>            }<br>        }<br>        else<br>        {<br>            LoadWidgets();<br>        }<br>    }<br><br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br>        <br>    }<br><br>    private void LoadWidgets()<br>    {<br>        //get the list of widgets that the user has<br>        List<WidgetUser> widgetList = WidgetUser.GetWidgetsByPortalUserId(thisUser.PortalUserId, connString);<br>        string title = string.Empty;<br>        string tag = string.Empty;<br>        <br>        //loop through the widgetList<br>        foreach (WidgetUser item in widgetList)<br>        {<br>            switch (item.WidgetId)<br>            {<br>                // customer widget<br>                case 1:<br>                    tag = "~/Desktop/Controls/Widgets/CustomerWidget.ascx";<br>                    title = Session["CID"].ToString();<br>                    CreateWidget(item, tag, title);                    <br>                    break;<br>                case 2:<br>                    tag = "~/Desktop/Controls/Widgets/WatchListWidget.ascx";<br>                    CreateWidget(item, tag, item.WidgetName);<br>                    break;<br>                case 3:<br>                    tag = "~/Desktop/Controls/Widgets/ManualCollectionWidget.ascx";<br>                    CreateWidget(item, tag, item.WidgetName);<br>                    break;<br>                case 4:<br>                    tag = "~/Desktop/Controls/Widgets/OnlineCollectionWidget.ascx";<br>                    CreateWidget(item, tag, item.WidgetName);<br>                    break;<br>                case 5:<br>                    break;<br>                case 6:<br>                    break;<br>                case 7:<br>                    break;<br>            }<br>            <br>        }<br>    }<br><br>    <br>    private void CreateWidget(WidgetUser item, string tag, string title)<br>    {<br>        string id = string.Format("Raddock{0}", item.WidgetId);<br>        //string title = Session["CID"].ToString();<br>        //string tag = "~/Desktop/Controls/Widgets/CustomerWidget.ascx";<br>        RadDock dock = CreateRadDock(id, title, 350, item, tag);<br><br>        Control widget = LoadControl(dock.Tag);<br>        dock.ContentContainer.Controls.Add(widget);<br>        <br>        AddDocktoZone(item.Column, dock);<br><br>        CreateSaveStateTrigger(dock);<br>    }<br><br>    private void AddDocktoZone(int column, RadDock dock)<br>    {<br>        if (column == 0)<br>        {<br>            RadDockZone0.Controls.Add(dock);<br>        }<br>        else if (column == 1)<br>        {<br>            RadDockZone1.Controls.Add(dock);<br>        }<br>        else if (column == 2)<br>        {<br>            RadDockZone2.Controls.Add(dock);<br>        }<br>    }<br><br>    private void CreateSaveStateTrigger(RadDock dock)<br>    {<br>        //Ensure that the RadDock control will initiate postback<br>        // when its position changes on the client or any of the commands is clicked.<br>        //Using the trigger we will "ajaxify" that postback.<br>        dock.AutoPostBack = true;<br>        dock.CommandsAutoPostBack = true;<br>    }<br><br>    private RadDock CreateRadDock(string id, string title, int width, WidgetUser item, string tag)<br>    {<br>        RadDock dock = new RadDock();<br>        dock.DockMode = DockMode.Docked;<br>        dock.UniqueName = item.WidgetUserId.ToString();<br>        dock.ID = string.Format("{0}_{1}", id, dock.UniqueName);<br>        dock.Title = title;<br>        dock.Index = item.Row;<br>        dock.Closed = !item.IsActive;<br>        dock.Collapsed = item.Collapsed;<br>        dock.Width = Unit.Pixel(width);<br>        dock.Tag = tag;<br>        dock.EnableAnimation = true;<br>        dock.Resizable = true;<br>                <br>        dock.Commands.Add(new DockCloseCommand());<br>        dock.Commands.Add(new DockExpandCollapseCommand());<br><br>        return dock;<br>    }<br>    protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)<br>    {<br>        //Populate the event args with the state information. The RadDockLayout control<br>        // will automatically move the docks according that information.<br>        foreach (DockState state in CurrentDockStates)<br>        {<br>            e.Positions[state.UniqueName] = state.DockZoneID;<br>            e.Indices[state.UniqueName] = state.Index;<br>        }<br>    }<br>    protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)<br>    {<br>        CurrentDockStates = RadDockLayout1.GetRegisteredDocksState();<br><br>        //save the layout to the database<br>        for (int i = 0; i < CurrentDockStates.Count; i++)<br>        {<br>            int index = CurrentDockStates[i].DockZoneID.Length-1;<br>            int column = Convert.ToInt32(CurrentDockStates[i].DockZoneID.Substring(index, 1));<br>            bool isActive = !CurrentDockStates[i].Closed;<br>            bool collapsed = CurrentDockStates[i].Collapsed;<br>            int widgetUserId = Convert.ToInt32(CurrentDockStates[i].UniqueName);<br>            WidgetUser.Update(widgetUserId, column, CurrentDockStates[i].Index, isActive, collapsed, connString);<br>        }<br><br>        if (Page.IsPostBack)<br>        {<br>            //LoadWidgets();<br>        }<br>    }<br><br>    private RadDock CreateRadDockFromState(DockState state)<br>    {<br>        RadDock dock = new RadDock();<br>        dock.DockMode = DockMode.Docked;<br>        dock.ID = string.Format("RadDock{0}", state.UniqueName);<br>        dock.ApplyState(state);<br>        dock.Commands.Add(new DockCloseCommand());<br>        dock.Commands.Add(new DockExpandCollapseCommand());<br><br>        return dock;<br>    }<br>}

Thanks,
NK

1 Answer, 1 is accepted

Sort by
0
Nagasree
Top achievements
Rank 1
answered on 09 May 2013, 04:27 PM
I was able to figure out the problem. I was assigning new value to the UniqueName property instead of using the one from the DockState. That fixed the problem.

Thanks,
NK
Tags
Dock
Asked by
Nagasree
Top achievements
Rank 1
Answers by
Nagasree
Top achievements
Rank 1
Share this question
or