Welcome Guest Search | Active Topics | Sign In | Register

TreeView: After ExpandPath is called Server Side TreeNode On Click not called Options
Mike
Posted: Friday, September 28, 2007 2:29:22 PM
Rank: Newbie
Groups: Member

Joined: 9/28/2007
Posts: 3
I am using the treeview control and have my page working quite nicely for browsing (from the root OnDemmand), now I would like to allow an entire path to be submitted and the tree be built out for that path. I have used the ExpandPath method of the trenode and it works, but after it is called I no longer receive my ItemClick server event.

Please advise of a work around or bug fix.
eo_support
Posted: Friday, September 28, 2007 8:36:20 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi Mike,

I am not sure where you call ExpandPath and the sequence of all the calls. ExpandPath itself should not affect item click. At the least extend I am thinking if you call ExpandPath after ItemClick is fired, then everything should be OK. The only tricky part about load on demand is that all load on demand calls will be "replayed" when the page postbacks, and when they replay, the need to replay out exactly the same way as it is originally populated. For example, considering the following sequence:

1. User is presented a TreeView containing a single root node A;
2. User expands the root node, your server side NodePopulate handler is called, you insert a child node B;
3. User expands that child node again, your server side NodePopulate handler is called again, you again inserted child node C, but this node is a leaf node and it can not be populated on demand;
4. User clicks node C, which causes the page to post back because you set RaisesServerEvent to true;
5. On the server side, the TreeView would first call your NodePopulate handler for root node A so that you can recreate node B, it then calls NodePopulate handler again with node B in order for you to recreate node C;
6. The TreeView triggers ItemClick event with node C;

Step 5 is the key step. If B or C is not correctly re-created, step 6 won't work because it can not find the node that raises the event.

Thanks
Mike
Posted: Monday, October 1, 2007 10:50:39 AM
Rank: Newbie
Groups: Member

Joined: 9/28/2007
Posts: 3
Thank-you for the response...

I have an ItemPopulate and an ItemClick eventhander. When the tree is completely user driven, starting at root node and expanding, and clicking on nodes everything works well.. When a node is clicked I display informatin about the node. In the ItemPopulate event I check if the node that is going to be populated already has child nodes, if so I do nothing. Example...

if (e.TreeNode.ChildNodes.Count <= 0)
{
if (Cluster.isCluster(e.TreeNode.Value))
{
bindClusterDirectory(e.TreeNode);
}
else
{
bindNetworkDirectoy(e.TreeNode);
}
}

I am not sure what you mean in terms of "the need to replay out exactly the same way as it is originally populated"? are you saying I have to go back to may datasource and rebuild all the nodes.. I can't do this, the performance would be terrible. I must not be understanding correctly as this code works currently, without "rebuilding all nodes".

What I want to do now is indstead of just browsing form the root node I want the tree to be displayed "expanded to a specific node" so if the tree is empty and then there is a postback (or the page is loaded for the first time) I can build out the tree and expand to a node, so when the page renders the tree is expanded out to the node.

So now in the code, I build out the tree (recursively) using the same method as nodePopulate and when I get to my leaf node I call node.ExpandPath(), and sure enough when the page renders my tree looks exaclty as I would expect. BUT now the ItemClick event doesn't get called for any nodes?? Even if I use the exact same code without the call to ExpandPath() - so it builds out the tree, but it is not expanded when it renders everything works ok.

It seems that mixing LoadOnDemmand and buiulding all nodes progmatically is casuing me a problem? make sense?

Thanks,

Mike
eo_support
Posted: Monday, October 1, 2007 11:48:07 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi Mike,

I see what you mean. You won't be able to do that in Page_Load, at which point its already too late --- in another word, nodes populated during page load will not be recognized as a source node to trigger item click event. That's why usually you should always reply on ItemPopulate event.

One thing you can try is to trigger the event from client side by JavaScript. In order to do that you will need to do:

1. Set RaisesServerEvent to false;
2. Provide a client side JavaScript function name to ClientSideOnItemClick;
3. Inside that function, you can then get the id or the path of the clicked node, then pass it back to the server side, using either our Callback control or call __doPostBack directly;

Both ways should get the control back to the server side with the information attached. You will then use that information to identify which item is being clicked and carry out whatever operation you want to carry.

Thanks
Mike
Posted: Wednesday, October 3, 2007 11:10:25 AM
Rank: Newbie
Groups: Member

Joined: 9/28/2007
Posts: 3
My results are inconsistent with your response.

Loading my nodes in "Page_Load" does not cause any problem with the Item_Click event. I load up many nodes and I still get my Item_Populate and Item_Click events as if they were loaded (initiated) by the user.

My only issue is the call to ExpandPath() seems to break that funcationality.

Is it possible to load a set of nodes in page_load and expand to a given path (using any method)? If so, do you have an example code? If not, what can be done?

I would prefer not to implement my own Item_Click to work around the ExpandPath() call.

Isn't the method above (steps 1,2,3) the way Item_Click already works? why does this need to be implemented manually?

Thank you for the continued support,

Mike
eo_support
Posted: Wednesday, October 3, 2007 11:39:48 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi Mike,

You might still have some problems with the replay part. The only scenario when ExpandPath affects Item_Click is when it affects replay. As such it appears that the replay has been working just fine for you. It is the replay part, not Page_Load part that actually helped you triggering the Item_Click event. However when you calls ExpandPath it breaks the replay part, so Item_Click event stops working for you.

It's essential to understand how the replay part works. I would recommend you to start a blank page, put a TreeView with a single root node and set its PopulateOnDemand to true. Provide it a PopuplateOnDemand handler and then step through the code in debugger to observe the 6 steps I outlined in my original reply. Since you still seem to be rather confused about it, it's kind of hard for us to explain this particular behavior to you. Everything will be much clearer once you observe all the steps I outlined in my first post in a debugger.

The reason that ExpandPath affects replay is, once an item is expanded, it is considered "already expanded" and no longer considered eligible for populate on demand. So its important that you don't change the expand status of a populate on demand node.

Step 1, 2, 3 in my previous post is totally different than the way Item_Click works. The reason that your Item_Click is not firing is not because the page didn't postback, but because the code can not find the item that triggered the event (because replay didn't work correctly, as explained). The method in my previous post offers a way to trigger server side event (not Item_Click event) without needing to find the triggering item.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.