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

Move/update dock results in reload of entire page

2 Answers 87 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 17 Jul 2012, 08:39 PM
This is probably a classic issue regarding update of dock content, but I can't get the docks to update or move the docks without the entire page is reloaded.

My code is base on an example I found here in the forum written by Telerik, and I have only made a few modifications.

I have moved public List<DockState> GetCurrentDockStates(string userkey, string frmName) to a widget class.

On page_init the docks are initiated from state. On page_load docks that are not in state are initiated and ascx controls are then loaded for all docks. 

I have 2 main problems.

1. I can't move or minimize a dock without the entire page reloads. If it isn't possible to move one dock without having to recreate all docks registered in the given RadDockLayout when I want to save the state (which is what I'm doing now), that is fine if just the RadDock components and their content is reloaded but the top menu and the rest of the page isn't. How can I change my code to achieve that?

2. I can't update the content of one dock without the entire page reloads. How can I update the content of one dock without the other docks or other page content is reloaded?

Hope someone here can help me out.

Thanks.

/Thomas


Widget class .aspx

        public List<DockState> GetCurrentDockStates(string userkey, string frmName)
        {
            //Get saved state string from the database - set it to dockState variable for example
            string dockStatesFromDB = "";
            dockStatesFromDB = DbUtils.GetUserSettings(userkey, frmName, settingsKey);
            List<DockState> _currentDockStates = new List<DockState>();
            if ((dockStatesFromDB != null) && (dockStatesFromDB != ""))
            {
                string[] stringStates = dockStatesFromDB.Split(';');
                foreach (string stringState in stringStates)
                {
                    if (stringState.Trim() != string.Empty)
                    {
                        _currentDockStates.Add(DockState.Deserialize(stringState));
                    }
                }
            }
            return _currentDockStates;
        }


Default.aspx.cs

 

    protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
    {
            Widget _widget = new Widget();
            List<DockState> _currentDockStates = _widget.GetCurrentDockStates((Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).KeyID, DebugFormName);
            foreach (DockState state in _currentDockStates)
            {
                e.Positions[state.UniqueName] = state.DockZoneID;
                e.Indices[state.UniqueName] = state.Index;
            }
    }

    protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
    {

        List<DockState> stateList = RadDockLayout1.GetRegisteredDocksState();

        StringBuilder serializedList = new StringBuilder();

        Widget _widget = new Widget();
        List<DockState> _currentDockStates = _widget.GetCurrentDockStates((Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).KeyID, DebugFormName);
        bool state_closed;
        foreach (DockState _dockState in stateList)
        {
            state_closed = false;
            foreach (DockState _dockState2 in _currentDockStates)
            {
                if (_dockState2.UniqueName == _dockState.UniqueName)
                {
                    if (_dockState2.Closed)
                    {
                        state_closed = true;
                        serializedList.Append(_dockState2.ToString());
                        serializedList.Append(";");
                    }
                }
            }
            if (!state_closed)
            {
                serializedList.Append(_dockState.ToString());
                serializedList.Append(";");
            }
        }

        string dockState = serializedList.ToString();
        if (dockState.Trim() != String.Empty)
        {
            DbUtils.SetUserSetting((Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).KeyID, "Default", "WidgetState", dockState);
        }

    }

    private RadDock CreateRadDockFromState(DockState state)
    {
        Widget widget = new Widget();
        XPOWidgetSettings xpoWidgetSettings = widget.getWidgetSettingsObjectById(state.UniqueName);

        RadDock dock = new RadDock();
        dock.DockMode = DockMode.Docked;
        dock.ID = string.Format("RadDock{0}", state.UniqueName);
        dock.ApplyState(state);
        DockExpandCollapseCommand cmd = new DockExpandCollapseCommand();
        dock.Commands.Add(cmd);
        return dock;
    }

    private RadDock CreateRadDock(string oid, string displayName, string widgetSettings)
    {
        RadDock dock = new RadDock();
        dock.DockMode = DockMode.Docked;
        dock.UniqueName = oid;
        dock.ID = string.Format("RadDock{0}", dock.UniqueName);

        DockCloseCommand closeCmd = new DockCloseCommand();
        dock.Commands.Add(closeCmd);
        DockExpandCollapseCommand cmd = new DockExpandCollapseCommand();
        dock.Commands.Add(cmd);

        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;

        AjaxUpdatedControl updatedControl = new AjaxUpdatedControl();
        updatedControl.ControlID = "Panel1";

        AjaxSetting setting1 = new AjaxSetting(dock.ID);
        setting1.EventName = "DockPositionChanged";
        setting1.UpdatedControls.Add(updatedControl);

        AjaxSetting setting2 = new AjaxSetting(dock.ID);
        setting2.EventName = "Command";
        setting2.UpdatedControls.Add(updatedControl);

        RadAjaxManager1.AjaxSettings.Add(setting1);
        RadAjaxManager1.AjaxSettings.Add(setting2);
    }

    private void LoadUserWidgets()
    {
        Widget widget = new Widget();
        string radDockID;
        string displayName;
        string settingString;

        List<DockState> _currentDockStates = widget.GetCurrentDockStates((Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).KeyID, DebugFormName);
        XPCollection widgetSettingsObjectsByUserLevel = widget.getWidgetSettingsObjectsByUserLevel((Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).Userrole);

        Boolean _doContinue;
        foreach (XPOWidgetSettings _widgetSetting in widgetSettingsObjectsByUserLevel)
        {
            _doContinue = false;
            radDockID = _widgetSetting.Oid.ToString();
            displayName = _widgetSetting.DisplayName;
            settingString = _widgetSetting.Settings;

            foreach (DockState _ds in _currentDockStates)
            {
                if (_ds.UniqueName == radDockID)
                    _doContinue = true;
            }
            if (_doContinue) continue;
            RadDock dock = CreateRadDock(radDockID, displayName, settingString);
            //find the target zone and add the new dock there

            //adding the dock to the docklayout and then docking it to the zone to avoid ViewState issues on subsequent postback
            RadDockLayout1.Controls.Add(dock);

            dock.Dock(DZCenter);

 

            CreateSaveStateTrigger(dock);

            //Load the selected widget in the RadDock control
            dock.Tag = _widgetSetting.AscxFile;
            LoadWidget(dock);
        }
    }

    private void LoadWidget(RadDock dock)
    {
        string siteUrl = TCFramework.TCConfigSettings.HostUrlGroups + Session[TCSessionConst.SessionFrmDefault_SelGroup];
        string userName = (Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).Username;
        string password = (Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).GetPassword();
        string ascxFile = "";
        string settings = "";

        string oId = dock.UniqueName;

        Widget widget = new Widget();
        XPOWidgetSettings xpoWidgetSettings = widget.getWidgetSettingsObjectById(oId);

        ascxFile = xpoWidgetSettings.AscxFile;
 settings = xpoWidgetSettings.Settings;

        Control widgetControl = LoadControl(ascxFile);
        if (widgetControl != null)
         dock.ContentContainer.Controls.Add(widgetControl);
    }

    private void CreateDocksFromStateDB()
    {
        Widget _widget = new Widget();
        List<DockState> _currentDockStates = _widget.GetCurrentDockStates((Session[TCSessionConst.SessionFrmDefault_XpoUser] as XpoUser).KeyID, DebugFormName);
        for (int i = 0; i < _currentDockStates.Count; i++)
        {
            RadDock dock = CreateRadDockFromState(_currentDockStates[i]);
            dock.Visible = !_currentDockStates[i].Closed;
            RadDockLayout1.Controls.Add(dock);

            //We want to save the dock state every time a dock is moved.

            if (dock.Visible) CreateSaveStateTrigger(dock);
        }
    }

 

    protected void Page_Init(object sender, EventArgs e)
    {
        CreateDocksFromStateDB();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (RadDock _rd in RadDockLayout1.RegisteredDocks)
            try
            {
                LoadWidget(_rd);
            }
            catch
            {
                //error in loading widget _rd.
            }

        if (!IsPostBack)
        {
            LoadUserWidgets();
        }
    }


Default.aspx

    <div>
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server"
            onloaddocklayout="RadDockLayout1_LoadDockLayout"
            onsavedocklayout="RadDockLayout1_SaveDockLayout">
            <table width="100%" cellpadding="12px">
                <tr>
                    <td width="25%" valign="top">
                        <telerik:RadDockZone ID="DZLeft" runat="server" BackColor="#BFDBFF"
                            ForeColor="#BFDBFF">
                        </telerik:RadDockZone>
                    </td>
                    <td width="50%" valign="top">
                        <telerik:RadDockZone ID="DZCenter" runat="server" BackColor="#BFDBFF"
                            Visible="True" ForeColor="#BFDBFF">
                        </telerik:RadDockZone>
                    </td>
                    <td width="25%" valign="top">
                        <telerik:RadDockZone ID="DZRight" runat="server" BackColor="#BFDBFF"
                            ForeColor="#BFDBFF">
                        </telerik:RadDockZone>
                    </td>
                </tr>
            </table>
        </telerik:RadDockLayout>
    </div>
    <div style="width: 0px; height: 0px; overflow: hidden; position: absolute; left: -10000px;">
        Hidden UpdatePanel, which is used to help with saving state when minimizing, moving
        and closing docks. This way the docks state is saved faster (no need to update the
        docking zones).
        <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        </asp:UpdatePanel>
    </div>

2 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
answered on 19 Jul 2012, 08:59 AM
I had an error in my private void CreateSaveStateTrigger(RadDock dock) which caused the entire reload of page when a dock was moved.
0
Shirlee
Top achievements
Rank 1
answered on 15 Dec 2016, 10:57 AM

Hi Thomas,

I have the same problem where all my docks are reloaded when I update a dock, close a dock and unpin/pin the dock. 

May I know what is your error in your CreateSaveStateTrigger(RadDock dock) that caused the entire reload of the page?

I know this is an old post but I'm still hoping you can reply back. Thanks.

Tags
Dock
Asked by
Thomas
Top achievements
Rank 1
Answers by
Thomas
Top achievements
Rank 1
Shirlee
Top achievements
Rank 1
Share this question
or