Thanks to anyone that can help me with this. Before laying out the problem I'm having, I should mention that my project is a web part designed for a Sharepoint Portal. From what I can tell, that limits me to a non-visual implementation of the treeview
and forces me to do everything in a sort of a "code behind" page.
With that said, I have been able to successfully implement the treeview into a web part and it works quite well. The issue I'm having is that the code that generates my tree takes a little while to run and I'd like to minimize the number of postbacks.
More specifically, I would like to limit postbacks to "selectedindexchanged" events only. The problem is that this control appears to be "all or nothing" in terms of events. In other words, if I set autopostback to "false", I can't get the selectedindexchanged
event to fire. If I set autopostback to "true", I get a postback on node expand and collapse events as well as the index changed event.
So, the question is... can I:
- somehow manually force a postback for the selectedinexchanged event when the autopostback is set to "false" or...
- somehow disable the postback for the expand/collapse events when the autopostback is set to "true"?
The best one I found was offered by persky. To use it, backup the treeview.htc file and then open it with notepad or some other text editor. Find the function "nodePlusMinusClick" and replace the entire function with the following code:
function nodePlusMinusClick()
{
if (g_bInteractive == false)
return;
var el = this.parentElement.treenode;
// 2 lines below commented out to disable postback on expand/collapse, extra lines added below for better functionality
// if (doNodePlusMinusClick(el) == true)
// fireQueuedEvents();
var index = getNodeIndex(el);
// if the selected or hovered node was one of the collapsed node's descendants then postback anyway
if (selectedNodeIndex.length > index.length && selectedNodeIndex.substr(0,index.length) == index)
{
if (doNodePlusMinusClick(el) == true)
fireQueuedEvents();
}
// otherwise just do the expand/collapse stuff
else
doNodePlusMinusClick(el);
}
You can disable postbacks for expand/collapse events by Setting the property TreeNode.SelectAction = TreeNodeSelectAction.Expand. This will cause the treenodes to expand/collapse without a postback. If you want to enable postback for a particular node,
set the property TreeNode.SelectAction = TreeNodeSelectAction.Select or TreeNodeSelectAction.SelectExpand.
pmccoy
Member
20 Points
4 Posts
Disabling treeview events
Jul 24, 2006 02:14 AM|LINK
Thanks to anyone that can help me with this. Before laying out the problem I'm having, I should mention that my project is a web part designed for a Sharepoint Portal. From what I can tell, that limits me to a non-visual implementation of the treeview and forces me to do everything in a sort of a "code behind" page.
With that said, I have been able to successfully implement the treeview into a web part and it works quite well. The issue I'm having is that the code that generates my tree takes a little while to run and I'd like to minimize the number of postbacks. More specifically, I would like to limit postbacks to "selectedindexchanged" events only. The problem is that this control appears to be "all or nothing" in terms of events. In other words, if I set autopostback to "false", I can't get the selectedindexchanged event to fire. If I set autopostback to "true", I get a postback on node expand and collapse events as well as the index changed event.
So, the question is... can I:
- somehow manually force a postback for the selectedinexchanged event when the autopostback is set to "false" or...
- somehow disable the postback for the expand/collapse events when the autopostback is set to "true"?
- Pete
pmccoy
Member
20 Points
4 Posts
Re: Disabling treeview events
Jul 24, 2006 01:42 PM|LINK
vishalDotNet
Member
5 Points
1 Post
Re: Disabling treeview events
Aug 01, 2006 04:37 AM|LINK
hi brother ,
i am also facing the same issue , could you please help me to come out of it or gimme the link of he post that solved your issue.
pmccoy
Member
20 Points
4 Posts
Re: Disabling treeview events
Aug 01, 2006 12:46 PM|LINK
This link has several solutions: http://forums.asp.net/thread/469254.aspx
The best one I found was offered by persky. To use it, backup the treeview.htc file and then open it with notepad or some other text editor. Find the function "nodePlusMinusClick" and replace the entire function with the following code:
function nodePlusMinusClick() { if (g_bInteractive == false) return; var el = this.parentElement.treenode; // 2 lines below commented out to disable postback on expand/collapse, extra lines added below for better functionality // if (doNodePlusMinusClick(el) == true) // fireQueuedEvents(); var index = getNodeIndex(el); // if the selected or hovered node was one of the collapsed node's descendants then postback anyway if (selectedNodeIndex.length > index.length && selectedNodeIndex.substr(0,index.length) == index) { if (doNodePlusMinusClick(el) == true) fireQueuedEvents(); } // otherwise just do the expand/collapse stuff else doNodePlusMinusClick(el); }ashwn_achary...
Member
2 Points
1 Post
Re: Disabling treeview events
Nov 01, 2007 01:22 PM|LINK
Hi,
You can disable postbacks for expand/collapse events by Setting the property TreeNode.SelectAction = TreeNodeSelectAction.Expand. This will cause the treenodes to expand/collapse without a postback. If you want to enable postback for a particular node, set the property TreeNode.SelectAction = TreeNodeSelectAction.Select or TreeNodeSelectAction.SelectExpand.
I hope this solves your problem. Cheers!!!
mohi
Member
11 Points
43 Posts
Re: Disabling treeview events
Nov 26, 2009 05:18 PM|LINK
thanks that worked