This is a migrated thread and some comments may be shown as answers.

Setting / Reseting Attributes in Client-Side Code

1 Answer 57 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 21 May 2008, 01:03 AM
I have a problem with the ScrollIntoView() method in that it is acting erratically.  Initially I had implemented this code:

    function pageLoad()
    {
     setTimeout('ScrollToSelectedNode()', 200);
    }

    function ScrollToSelectedNode()
    {
      var tree = <%= treeViewMain.ClientID %>;
      var selectedNode = tree.SelectedNode; 

      if (selectedNode != null)
         selectedNode.ScrollIntoView();
    }

But thinking about my application some, I realized that the ONLY time I needed ScrollIntoView() to be used was when I moved a node from one part of the main tree to another.  So in my server-side code I added this:

    nodeToMove.Attributes.Add("Moved", "1");

And then I altered the latter function like this:

    function ScrollToSelectedNode()
    {
      var tree = <%= treeViewMain.ClientID %>;
      var selectedNode = tree.SelectedNode;

      if (selectedNode != null && selectedNode.Attributes.Moved == "1")
      {
        selectedNode.ScrollIntoView();
        selectedNode.Attributes.Moved = "0";
      }
    }


My problem is this: I tried to remove the "Moved" attribute but couldn't figure out how.  And then when its value was [supposedly] set to "0" it didn't "stick".  On the next partial-postback its value had returned to "1" ... for reasons I don't understand.

Might anyone have any ideas?

Robert

1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 21 May 2008, 06:10 AM
Please ignore, as I resolved by using an independent ASP.Net hidden variable.  Why the tree's attributes aren't being maintained between postbacks I do not know but I'm just happy I found another way to solve it.

Using this hidden variable, I only use the ScrollIntoView function when I move a node.  Otherwise, I do not call the function.

Robert
Tags
TreeView
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or