save raddock state in Database

2 posts, 0 answers
  1. Roukaya
    Roukaya avatar
    17 posts
    Member since:
    Aug 2012

    Posted 01 Jun 2012 Link to this post

    hello all ,
    i want a sample example to know how to save state of raddock and Radzone in database (set and get state into and from database ) , not in cookies like used in telerik help documentation (this one )
    Is there any sample project to do that ???

    thanks in advance
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Jun 2012 Link to this post

    Hi Roukaya,

    Try the following code snippet to save and load state of RadDock in database.

    C#:
    private List<DockState> CurrentDockStates
            {
                get
                {
                    //Get saved state string from the database - set it to dockState variable for example
                    string dockStatesFromDB = "";
                    _conn.Open();
                    SqlCommand command = new SqlCommand("select State from States where id='" + _userID + "' ", _conn);
                    dockStatesFromDB = command.ExecuteScalar().ToString();
                    _conn.Close();
                    List<DockState> _currentDockStates = new List<DockState>();
                    string[] stringStates = dockStatesFromDB.Split('|');
                    foreach (string stringState in stringStates)
                    {
                        if (stringState.Trim() != string.Empty)
                        {
                            _currentDockStates.Add(DockState.Deserialize(stringState));
                        }
                    }
                    return _currentDockStates;
                }
            }
     
     
    protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
            {
                List<DockState> stateList = RadDockLayout1.GetRegisteredDocksState();
                StringBuilder serializedList = new StringBuilder();
                int i = 0;
                while (i < stateList.Count)
                {
                    serializedList.Append(stateList[i].ToString());
                    serializedList.Append("|");
                    i++;
                }
                string dockState = serializedList.ToString();
                if (dockState.Trim() != String.Empty)
                {
                    _conn.Open();
                    SqlCommand command = new SqlCommand(String.Format("update States set State='{0}' where id='" + _userID + "'", dockState), _conn);
                    command.ExecuteNonQuery();
                    _conn.Close();
                }
            }
    protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
            {
                //Populate the event args with the state information. The RadDockLayout control
                // will automatically move the docks according that information.
                foreach (DockState state in CurrentDockStates)
                {
                    e.Positions[state.UniqueName] = state.DockZoneID;
                    e.Indices[state.UniqueName] = state.Index;
                }
            }

    I tried this based on the following code libraries. Please have a look into them.

    Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel
    Save DockState in DataBase using RadAjaxManager

    Regards,
    Princy.
Back to Top