How to stop PostBack for Treeview control
-
Hi friends, I'm using asp.net 2.0 Treeview control. This control have some rootnodes and child nodes. on clicking any node(either parent or child node) page is getting refreshed. I want to stop the postback and node should be selected. After selecting the node, in "ADD" button click event i want to catch which node is selected. Anybody already worked with this type of requirement plz help me. Thanks in Advance Hari
-
Hi friends, I'm using asp.net 2.0 Treeview control. This control have some rootnodes and child nodes. on clicking any node(either parent or child node) page is getting refreshed. I want to stop the postback and node should be selected. After selecting the node, in "ADD" button click event i want to catch which node is selected. Anybody already worked with this type of requirement plz help me. Thanks in Advance Hari
-
Hi AhsanS, Thanks for the response but there is no AutoPostBack Property for Treeview control. :)
modified on Thursday, March 13, 2008 8:54 AM
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); }
Ahsan Ullah Senior Software Engineer
-
Hi AhsanS, Thanks for the response but there is no AutoPostBack Property for Treeview control. :)
modified on Thursday, March 13, 2008 8:54 AM
there is another solution as well. When you are adding the nodes do this 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.
Ahsan Ullah Senior Software Engineer
-
Hi friends, I'm using asp.net 2.0 Treeview control. This control have some rootnodes and child nodes. on clicking any node(either parent or child node) page is getting refreshed. I want to stop the postback and node should be selected. After selecting the node, in "ADD" button click event i want to catch which node is selected. Anybody already worked with this type of requirement plz help me. Thanks in Advance Hari
Hi Kuricheti, There is no AutoPostBack event in Treeview control. To get the selected text you can use OnSelectedNodeChanged property in .aspx file and point it to some function. eg. OnSelectedNodeChanged="SelectCategory"> to get the selected value write a function in C# and use TREEVIEWID.SelectedNode.Text eg. tbCategory.Text = tvCategories.SelectedNode.Text; Try it out.