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

parall zones created dynamically

1 Answer 20 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Golu
Top achievements
Rank 1
Golu asked on 25 May 2009, 09:28 AM

Dear sir,


I am creating fully customizes Dashboard.

I am creating a RadDockZones dynamically successfuly.and I want to add zones on user demand.
if user enter 1 row with 2 zones then it created 2 zones in a row if user enter 1 row with 1 zone then only single zone is added on a row.

added 2 zoned in a row and give both zone names in dropdownlist, according to selected index change user add dock ( which zone name is seleted from DDL).
I am trying but not getting i thnk missing something, will you please send me code ( but plz its fully dunamic)

accoring to my code it created 2 zones parall but dock not added parall...plz check my code and loading panel also  not working. (I am remove all ajaxing all working on buttons click)

sir plz answeing me ASAP our deadline is very very close.

our code as follows..
aspx..
<table width="100%" border="1" cellpadding="1" cellspacing="0" class="aspxMainTable">
        <tr>
            <th class="tdMainHeader1">
                <img alt="Customer" src="Images/dashboard.gif" />
                Dashboard &nbsp;&nbsp;&nbsp;
                <%--Zone Width :--%><telerik:RadTextBox ID="txtZoneWidth" runat="server" Width="150px"
                    Visible="false">
                </telerik:RadTextBox>
                &nbsp; Zone Layout
                <telerik:RadComboBox ID="cmbZoneLayout" runat="server">
                    <Items>
                        <telerik:RadComboBoxItem Text="Select" Value="" Selected="true" />
                        <telerik:RadComboBoxItem Text="1 Row 1 column" Value="1,1" />
                        <telerik:RadComboBoxItem Text="1 Row 2 Column" Value="1,2" />
                    </Items>
                </telerik:RadComboBox>
                <asp:Button ID="btnAddZone" runat="server" Text="Add Zone" OnClick="btnAddZone_Click"
                    Width="100px" />
                <%--OnClientClick="return ZoneWidthValidation();"--%>
                Objects &nbsp;
                <telerik:RadComboBox ID="cmbSelectDock" runat="server" Skin="Office2007">
                    <Items>
                        <telerik:RadComboBoxItem Text="Case Summary" Value="CaseSummary" />
                        <telerik:RadComboBoxItem Text="Task Summary" Value="TaskSummary" />
                        <telerik:RadComboBoxItem Text="Pending Tasks" Value="MyTask" />
                        <telerik:RadComboBoxItem Text="Pending Cases" Value="MyCase" />
                        <telerik:RadComboBoxItem Text="Overdue Cases" Value="OverdueCases" />
                    </Items>
                </telerik:RadComboBox>
                &nbsp;
                <telerik:RadComboBox ID="cmbZone" runat="server" Skin="Office2007">
                </telerik:RadComboBox>
                &nbsp;
                <asp:Button ID="btnAddDock" runat="server" Text="Add Dock" Width="100px" OnClick="btnAddDock_Click" /><%-- OnClientClick="return ValidateSave();"--%>
                &nbsp;
                <asp:Button ID="btnSaveDock" runat="server" Text="Save State" Width="100px" OnClick="btnSaveDock_Click" />
            </th>
        </tr>
        <tr>
            <td>
                <telerik:RadDockLayout runat="server" ID="rdDockLayout" OnSaveDockLayout="rdDockLayout_SaveDockLayout"
                    Skin="Office2007" OnLoadDockLayout="rdDockLayout_LoadDockLayout">
                </telerik:RadDockLayout>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblMessage" runat="server"></asp:Label>
            </td>
        </tr>
    </table>

aspx.cs......
int i = 0;
    int tempID;

    string dockState = "";
    string strDockTag = string.Empty;
    string strZone = string.Empty;
    string strZoneName = string.Empty;
    string strDockTagName = string.Empty;
    string strResult = string.Empty;

    DockStateWS objDockStateWS;
    DataSet dsDataSet;
    List<DockState> stateList;
    List<string> zoneList;
    StringBuilder serializedList = new StringBuilder();
    ArrayList zones = new ArrayList();

    private List<DockState> CurrentDockStates
    {
        get
        {
            List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStatesMyPortal"];
            if (Object.Equals(_currentDockStates, null))
            {
                _currentDockStates = new List<DockState>();
                Session["CurrentDockStatesMyPortal"] = _currentDockStates;
            }
            return _currentDockStates;
        }
        set
        {
            Session["CurrentDockStatesMyPortal"] = value;
        }
    }

    private List<string> CurrentDockZoneIds
    {
        get
        {
            List<string> _currentDockZoneIds = (List<string>)Session["CurrentDockZoneIds"];
            if (Object.Equals(_currentDockZoneIds, null))
            {
                _currentDockZoneIds = new List<string>();
                Session["CurrentDockZoneIds"] = _currentDockZoneIds;
            }
            return _currentDockZoneIds;
        }
        set
        {
            Session["CurrentDockZoneIds"] = value;
        }
    }

    protected void Page_InIt(object sender, EventArgs e)
    {
        try
        {
            objDockStateWS = new DockStateWS();
            dsDataSet = new DataSet();

            dsDataSet = objDockStateWS.Fetch_Zones(0, 2,"1");

            if (dsDataSet.Tables["DockZones"].Rows.Count > 0)
            {
                for (int i = 0; i < dsDataSet.Tables["DockZones"].Rows.Count; i++)
                {
                    strZone = Convert.ToString(dsDataSet.Tables["DockZones"].Rows[i]["zone_control_id"]);
                    strZoneName = Convert.ToString(dsDataSet.Tables["DockZones"].Rows[i]["zone_control_name"]);                  
                    CreateRadDockZone(strZone,strZoneName);
                }
            }

            for (int i = 0; i < CurrentDockStates.Count; i++)
            {
                if (CurrentDockStates[i].Closed == false)
                {
                    RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
                    rdDockLayout.Controls.Add(dock);
                    LoadWidget(dock);
                }
            }
        }
        catch (Exception ex)
        {
            LogMessage(ex, 1, "Page_InIt");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        //--counter for RadDockZone Name
        if (Convert.ToString(ViewState["Counter"]) == "")
        {
            tempID = 0;
        }
        else
        {
            tempID++;
        }

        if (!Page.IsPostBack)
        { 
            //-- from database
            try
            {
                GetZones();
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "errMsg", "javascript:alert(\"Error:-Method -> 'Page_Init' \\n Description:- \\n" + ex.Message + "\");", true);
                return;
            }
        }
    }

    protected void rdDockLayout_LoadDockLayout(object sender, DockLayoutEventArgs e)
    {
        bool bDocStateCreate = false;
       
        //--from database
        DataTable dt = new DataTable();       

        try
        {
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            //--use session
            foreach (DockState state in CurrentDockStates)
            {
                bDocStateCreate = true;
                e.Positions[state.UniqueName] = state.DockZoneID;
                e.Indices[state.UniqueName] = state.Index;
            }

            if (bDocStateCreate == false)
            {
                objDockStateWS = new DockStateWS();
                dsDataSet = new DataSet();
                dsDataSet = objDockStateWS.Fetch_Dock_State(0, 2);

                if (dsDataSet.Tables["DockState"].Rows.Count > 0)
                {
                    dockState = Convert.ToString(dsDataSet.Tables["DockState"].Rows[0]["dock_state"]);
                    string[] currentDockStates = dockState.Split('|');
                    foreach (string stringState in currentDockStates)
                    {
                        if (stringState.Trim() != string.Empty)
                        {
                            serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                            DockState state = serializer.Deserialize<DockState>(stringState);
                            RadDock dock = CreateRadDockFromState(state);
                            rdDockLayout.Controls.Add(dock);
                            LoadWidget(dock);
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LogMessage(ex, 1, "rdDockLayout_LoadDockLayout");
        }
    }

    protected void rdDockLayout_SaveDockLayout(object sender, DockLayoutEventArgs e)
    {
        CurrentDockStates = rdDockLayout.GetRegisteredDocksState();
    }

    private RadDock CreateRadDockFromState(DockState state)
    {
        RadDock dock = new RadDock();
        dock.ID = string.Format("RadDock{0}", state.UniqueName);
        dock.ApplyState(state);
        dock.Command += new DockCommandEventHandler(dock_Command);
        dock.Commands.Add(new DockCloseCommand());
        dock.CommandsAutoPostBack = true;

        return dock;
    }

    void dock_Command(object sender, DockCommandEventArgs e)
    {
        if (e.Command.Name == "Close")
        {
////            ScriptManager.RegisterStartupScript
////            (
////                UpdatePanel1, this.GetType(), "RemoveDock",
////                string.Format(@"function _removeDock() {{
////                Sys.Application.remove_load(_removeDock);
////                $find('{0}').undock();
////                $get('{1}').appendChild($get('{0}'));
////                $find('{0}').doPostBack('DockPositionChanged');
////                }};
////                Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, UpdatePanel1.ClientID),
////                true
////             );
            ScriptManager.RegisterStartupScript
           (
               Page, this.GetType(), "RemoveDock",
               string.Format(@"function _removeDock() {{
                Sys.Application.remove_load(_removeDock);
                $find('{0}').undock();
                $get('{1}').appendChild($get('{0}'));
                $find('{0}').doPostBack('DockPositionChanged');
                }};
                Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, Page.ClientID),
               true
            );

        }
    }

    private RadDock CreateRadDock()
    {
        RadDock dock = new RadDock();
        dock.UniqueName = Guid.NewGuid().ToString();
        dock.ID = string.Format("RadDock{0}", dock.UniqueName);
        dock.Title = cmbSelectDock.SelectedItem.Text;
        dock.Text = string.Format("Added at {0}", DateTime.Now);
        dock.CommandsAutoPostBack = true;

        return dock;
    }

    private void CreateRadDockZone(string id, string name)
    {
        try
        {
            #region test code
            ///dynamica table           
            //if (cmbZoneLayout.SelectedValue == "1,2")
            //{             
                    RadDockZone zone1 = new RadDockZone();
                    RadDockZone zone2 = new RadDockZone();
                    if (id != null )
                    {
                        if (name == "RadDockZone0")
                            zone1.ID = id;
                        else if (name == "RadDockZone1")
                             zone2.ID = id;
                    }                   
                    else
                    {
                        zone1.UniqueName = "RadDockZone0";
                        zone1.ID = "RadDockZone0";
                        zone1.Width = Unit.Pixel(200);
                        zone1.FitDocks = true;
                        zone1.Orientation = Orientation.Horizontal;
                        zone1.Skin = "Office2007";
                        zone1.Style.Add("float", "left");
                        zone1.Style.Add("margin-right", "20px");

                        zone2.UniqueName = "RadDockZone1";
                        zone2.ID = "RadDockZone1";
                        zone2.Width = Unit.Pixel(200);
                        zone2.FitDocks = true;
                        zone2.Orientation = Orientation.Horizontal;
                        zone2.Skin = "Office2007";
                        zone2.Style.Add("float", "left");

                       
                        objDockStateWS = new DockStateWS();
                        dsDataSet = new DataSet();
                        if (zone1.ID != null)
                        {
                            dsDataSet = objDockStateWS.Save_Zone(0, 2, Convert.ToString(zone1.ID), "1", Convert.ToString(zone1.UniqueName));
                        }
                        if (zone2.ID != null)
                        {
                            dsDataSet = objDockStateWS.Save_Zone(0, 2, Convert.ToString(zone2.ID), "1", Convert.ToString(zone2.UniqueName));
                        }

                        //--if success          
                        if (dsDataSet.Tables["Response"].Rows[0]["ResultCode"].ToString() != "0")
                        {
                            strResult = dsDataSet.Tables["Response"].Rows[0]["ResultString"].ToString();
                            LogMessage(new Exception(strResult), 1, "CreateRadDockZone");
                            return;
                        }
                        else
                        {
                            RadComboBoxItem rdbItem = new RadComboBoxItem(zone1.UniqueName, zone1.ID);
                            cmbZone.Items.Insert(cmbZone.Items.Count, rdbItem);

                            RadComboBoxItem rdbItem2 = new RadComboBoxItem(zone2.UniqueName, zone2.ID);
                            cmbZone.Items.Insert(cmbZone.Items.Count, rdbItem2);
                        }
                    }
                    if (id != null)
                    {
                        if (name == "RadDockZone0")
                            rdDockLayout.Controls.Add(zone1);
                        else if (name == "RadDockZone1")
                            rdDockLayout.Controls.Add(zone2);
                    }
                    else
                    {
                        rdDockLayout.Controls.Add(zone1);
                        rdDockLayout.Controls.Add(zone2);
                    }
                   
            //}
        }
            #endregion

            #region original code
        //    RadDockZone zone1 = new RadDockZone();
        //    if (id != null)
        //    {
        //        zone1.ID = id;
        //    }
        //    else
        //    {
        //        zone1.UniqueName = "RadDockZone" + tempID;
        //        zone1.ID = "RadDockZone" + Guid.NewGuid();
        //        zone1.Width = Unit.Pixel(200);
        //        zone1.FitDocks = true;
        //        zone1.Orientation = Orientation.Horizontal;
        //        zone1.Skin = "Office2007";
        //        zone1.Style.Add("float", "left");
        //        zone1.Style.Add("margin-right", "20px");

        //        objDockStateWS = new DockStateWS();
        //        dsDataSet = new DataSet();

        //        dsDataSet = objDockStateWS.Save_Zone(0, 2, Convert.ToString(zone1.ID), "1", Convert.ToString(zone1.UniqueName));
        //        ViewState["Counter"] = tempID;

        //        //--if success          
        //        if (dsDataSet.Tables["Response"].Rows[0]["ResultCode"].ToString() != "0")
        //        {
        //            strResult = dsDataSet.Tables["Response"].Rows[0]["ResultString"].ToString();
        //            LogMessage(new Exception(strResult), 1, "CreateRadDockZone");
        //            return;
        //        }
        //        else
        //        {
        //            RadComboBoxItem rdbItem = new RadComboBoxItem(zone1.UniqueName, zone1.ID);
        //            cmbZone.Items.Insert(cmbZone.Items.Count, rdbItem);
        //        }
        //    }
        //    rdDockLayout.Controls.Add(zone1);
        //}
#endregion
        catch (Exception ex)
        {
            LogMessage(ex, 1, "CreateRadDockZone");
        }
    }

    private void LoadWidget(RadDock dock)
    {
        if (string.IsNullOrEmpty(dock.Tag))
        {
            return;
        }
        Control widget = LoadControl(dock.Tag);
        dock.ContentContainer.Controls.Add(widget);
    }

    protected void btnAddDock_Click(object sender, EventArgs e)
    {
        try
        {
            LoadUserControlsDynamically();
            RadDock dock = CreateRadDock();
            RadDockZone dz = (RadDockZone)rdDockLayout.FindControl(Convert.ToString(cmbZone.SelectedValue));
           
            dz.Controls.Add(dock);
            dock.Tag = strDockTag;
            LoadWidget(dock);
        }
        catch (Exception ex)
        {
            LogMessage(ex, 1, "btnAddDock_Click");
        }
    }

    void LogMessage(Exception e, Int32 param, string strMethodName)
    {
        if (param == 1)
        {
            lblMessage.Text = e.Message + "  Method:- " + strMethodName;
            lblMessage.CssClass = "error";
        }
        else
        {
            lblMessage.Text = e.Message;
            lblMessage.CssClass = "success";
        }
    }

    private void LoadUserControlsDynamically()
    {
        string strControlID = string.Empty;

        if (cmbSelectDock.SelectedValue == "CaseSummary")
        {
            UserControls_Case_Summary_CustCateg_Chart uclCaseSummary_Chart = (UserControls_Case_Summary_CustCateg_Chart)Page.LoadControl("~/UserControls/Case_Summary_CustCateg_Chart.ascx");
            strControlID = "uclCaseSummary_Chart" + TB_nUserID;
            uclCaseSummary_Chart.GetCaseSummary();
            strDockTag = "UserControls/Case_Summary_CustCateg_Chart.ascx";
        }
        else if (cmbSelectDock.SelectedValue == "TaskSummary")
        {
            UserControls_Task_Summary_Chart uclTaskSummary_Chart = (UserControls_Task_Summary_Chart)Page.LoadControl("~/UserControls/Task_Summary_Chart.ascx");
            strControlID = "uclTaskSummary_Chart" + TB_nUserID;
            uclTaskSummary_Chart.GetTaskSummary();
            strDockTag = "~/UserControls/Task_Summary_Chart.ascx";
        }
        else if (cmbSelectDock.SelectedValue == "MyTask")
        {
            UserControls_MyTask uclMyTask = (UserControls_MyTask)Page.LoadControl("~/UserControls/MyTask.ascx");
            strControlID = "uclTask" + TB_nUserID;
            uclMyTask.GetTasks();
            strDockTag = "~/UserControls/MyTask.ascx";
        }
        else if (cmbSelectDock.SelectedValue == "MyCase")
        {
            UserControls_MyCase uclMyCase = (UserControls_MyCase)Page.LoadControl("~/UserControls/MyCase.ascx");
            strControlID = "uclCase" + TB_nUserID;
            uclMyCase.GetCases();
            strDockTag = "~/UserControls/MyCase.ascx";
        }
        else if (cmbSelectDock.SelectedValue == "OverdueCases")
        {
            UserControls_OverdueCases uclOverdueCases = (UserControls_OverdueCases)Page.LoadControl("~/UserControls/OverdueCases.ascx");
            strControlID = "uclOverdueCase" + TB_nUserID;
            uclOverdueCases.GetOverDueCases();
            strDockTag = "~/UserControls/OverdueCases.ascx";
        }
    }

    protected void btnSaveDock_Click(object sender, EventArgs e)
    {
        try
        {
            //--Save Dock states in Database
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            stateList = rdDockLayout.GetRegisteredDocksState();

            while (i < stateList.Count)
            {
                serializedList.Append(serializer.Serialize(stateList[i]));
                serializedList.Append("|");
                i++;
            }

            dockState = serializedList.ToString();
            if (dockState.Trim() != String.Empty)
            {
                objDockStateWS = new DockStateWS();
                dsDataSet = new DataSet();
                dsDataSet = objDockStateWS.Save_Dock_State(0, 2, dockState);
            }
        }
        catch (Exception ex)
        {
            LogMessage(ex, 1, "btnSaveDock_Click");
        }
    }

    protected void btnAddZone_Click(object sender, EventArgs e)
    {
        CreateRadDockZone(null,null);
        zoneList = CurrentDockZoneIds;
    }

    private void GetZones()
    {
        objDockStateWS = new DockStateWS();
        dsDataSet = new DataSet();

        dsDataSet = objDockStateWS.Fetch_Zones(0, 2,"1");

        if (dsDataSet.Tables["DockZones"].Rows.Count > 0)
        {
            cmbZone.DataSource = dsDataSet;
            cmbZone.DataTextField = "zone_control_name";
            cmbZone.DataValueField = "zone_control_id";
            cmbZone.DataBind();
        }
    }

thanks with regards
 

1 Answer, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 27 May 2009, 01:40 PM
Hi Neha,

Please open a support ticket and send us a running project where we can observe the problem.Once we receive it we will do our best to help you.

Kind regards,
Petio Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Dock
Asked by
Golu
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Share this question
or