This is a migrated thread and some comments may be shown as answers.
How to preserve the state of the Toolbar Buttons between the Calls?
1 Answer 28 Views
This is a migrated thread and some comments may be shown as answers.
Sri
Top achievements
Rank 1
Sri asked on 25 Jun 2009, 06:30 PM
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?

Thanks
Sri K Gamini.

1 Answer, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 26 Jun 2009, 07:03 AM
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...
      function ChangeStateAllButtons(tb, state) { 
        // This function simply selectes each ToolbarItem and sets the enabled state. 
        if (tb == nullreturn
 
        tb.trackChanges(); 
        for (var i = 0; i < tb.get_items().get_count(); i++) { 
          var item = tb.get_items().getItem(i).set_enabled(state); 
        } 
        tb.commitChanges(); 
      } 
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.

--
Stuart

Asked by
Sri
Top achievements
Rank 1
Answers by
Stuart Hemming
Top achievements
Rank 2
Share this question
or