Treeview onselectedindexchange

Discussion in 'ASP .Net Web Controls' started by Graeme Coutts, Feb 8, 2005.

  1. 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?
    Graeme Coutts, Feb 8, 2005
    #1
    1. Advertising

  2. 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
    Mohamed El Ashmawy, Feb 8, 2005
    #2
    1. Advertising

  3. 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.

    ""Mohamed El Ashmawy"" wrote:

    > 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
    >
    >
    Graeme Coutts, Feb 8, 2005
    #3
  4. 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.


    "Graeme Coutts" wrote:

    > 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.
    >
    > ""Mohamed El Ashmawy"" wrote:
    >
    > > 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
    > >
    > >
    Graeme Coutts, Feb 8, 2005
    #4
  5. 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
    Mohamed El Ashmawy, Feb 17, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve roszko
    Replies:
    1
    Views:
    1,842
    steve
    Aug 12, 2003
  2. Replies:
    5
    Views:
    15,686
    cbDevelopment
    Dec 4, 2005
  3. VB Programmer

    OnSelectedIndexChange runs twice

    VB Programmer, Mar 22, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    437
    VB Programmer
    Mar 22, 2006
  4. MattB
    Replies:
    2
    Views:
    637
    MattB
    Oct 1, 2007
  5. steve

    Get value from datagrid cell OnSelectedIndexChange

    steve, Aug 12, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    113
    steve
    Aug 12, 2003
Loading...

Share This Page