Saving the state of the docks using AJAX

2 posts, 0 answers
  1. Martin
    Martin avatar
    84 posts
    Member since:
    Apr 2009

    Posted 17 Jun 2009 Link to this post

    I really don't want to do postback, because we have a lot of controls created programmatically.
    I see that through javascript I basically get the information I need:

     


    function
    OnClientDockPositionChanged(sender, args) {

     

    alert(sender.get_dockZoneID());

    alert(sender.get_uniqueID());

    alert(sender.get_collapsed());

    alert(sender.get_closed());

    }

    Do you have an example when the state of the docks is saved and loaded using web service call through AJAX's 

     

    PageMethods?

  2. Martin
    Martin avatar
    84 posts
    Member since:
    Apr 2009

    Posted 17 Jun 2009 Link to this post

    I got it accomplished, the saving works without a single postback.
    This is a much better solution then using the server side, which can become hell if you have lots of dynamically generated controls.

    So to recap you have to do the following:
    - declare all your zones
    - use get_docks for each zone and concat it to a master array
    - loop through that master array creating a custom JSON string with only three entries if you are only interested in positioning
    use a PageMethods web service call to save your selection in whatever storage media you desire Session, Cookies, DB
    - then add on Page_Init  LoadDockLayout
    - the LoadDockLayout event handler uses the standard load routine found in the doc

     

    if (!Page.IsPostBack)

     

    {

     

    String dockState = //your data media here
    if (dockState != null)

     

    {

     

    string serializedList = dockState;

     

     

    if (serializedList != null)

     

    {

     

    string[] states = serializedList.Split('|');

     

     

    for (int i = 0; i < states.Length; i++)

     

    {

     

    DockState state = DockState.Deserialize(states[i]);

     

    e.Positions[state.UniqueName] = state.DockZoneID;

    e.Indices[state.UniqueName] = state.Index;

    }

    }

    }

    works like a charm

Back to Top