Treeview onselectedindexchange

G

Graeme Coutts

I have a IE Treeview and I am trapping the onselectedindexchange event in a
JavaScript function by:

tree.Attributes.Add("onselectedindexchange",tree.ClientID+"_onchange();");

The JavaScript function simply reads the text of the new selected node and
then writes this to a text field. It looks like:

function tree_tree_onchange()
{
var tree;
var treenode;
tree=document.getElementById('tree_tree');
treenode=tree.getTreeNode(tree.selectedNodeIndex);
document.all.item('tree_text').value=treenode.getAttribute('Text');
}

Everything is working great except when I re-post the form to the server
(using a separate button control) the selectednodeindex that was set on the
client-side is lost. The tree conttrol returns to the default (first node) as
the selected node.

anyone got a solution for this so that I can retain the client-side
selection?
 
M

Mohamed El Ashmawy

You need to save the changes that you made on the client side and re-apply
them on post on the server side.
Thus, when the tree is rendered again after its post back, it'll be in a
state similar to the one before the postback

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
 
G

Graeme Coutts

I dont understand what you mean by 'you need to save the changes'. Im not
making any changes in the client-side - simply reading the selected node text
and writing this to another text field.
 
G

Graeme Coutts

I found a solution to the problem.

If you are over-ride the events then be sure to queue the base events in
order to maintain the state. At the end of your onselectedindexchange event
add the following lines:

if (event.oldTreeNodeIndex != event.newTreeNodeIndex)
tree.queueEvent('onselectedindexchange', event.oldTreeNodeIndex + ',' +
event.newTreeNodeIndex);

Upon next server re-post the state is preserved.
 
M

Mohamed El Ashmawy

I am sorry I misunderstood your question.
I thought you meant that you apply some changes on the client side using
javascript code and you would like to persist the changes that you made
upon postbacks.

Congrats for solving the problem
Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top