How to preserve the state of the Toolbar Buttons between the Calls?

2 posts, 0 answers
  1. Sri
    Sri avatar
    22 posts
    Member since:
    Jun 2009

    Posted 25 Jun 2009 Link to this post

    I have a Toolbar Control in a Update Panel and a TreeView Control in another Update Panel.
    By default in the Server code, I disabled all the buttons, but using the Node Clicking event of the TreeView Control, I am managing the buttons on the Toolbar enabling few and disabiling few.

    The issue is, when I select a Node, Click a button on the toolbar, after executing the functionality all the buttons in the Toolbar are disabled. After doing some research I found that the State is not maintained on the toolbar as the enable and disable I am doing in the javascript using OnNodeClicking event.

    How can I resolve the issue? How can I make the toolbar remember the settings between the calls?

    Sri K Gamini.
  2. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 26 Jun 2009 Link to this post

    Hi there.

    The simple answer is "yes".

    So, how do you do it? Well, all you need do is wrap the JavaScript code you use for changing the status of the buttons with calls to the toolbar's trackChanges and commitChanges methods.

    Here's a simple example from a project I'm working on ATM...
    1       function ChangeStateAllButtons(tb, state) { 
    2         // This function simply selectes each ToolbarItem and sets the enabled state. 
    3         if (tb == nullreturn
    5         tb.trackChanges(); 
    6         for (var i = 0; i < tb.get_items().get_count(); i++) { 
    7           var item = tb.get_items().getItem(i).set_enabled(state); 
    8         } 
    9         tb.commitChanges(); 
    10       } 
    Lines 5 and 9 are the important ones here.

    You need to do this if you'rte adding or removing buttons client-side and where you want the changes to be remembered after a postback.

    There's more info on this help page. Go to the end of the page and look for "Preserving Changes".

    I hope this helps.


Back to Top