How to set treeview's childnode postback false on ASP.NET?

女生的网名这么多〃 提交于 2019-12-06 15:40:49

You can set CSSClass of treeview child nodes like

      <asp:TreeView LeafNodeStyle-CssClass="childnode" runat="server">....</asp:TreeView>

then using jquery you get get class and set return false like follow.

      $(".childnode").click(function(){
                 return false;
      })

...same way you can set RootNodeStyle-CssClass, ParentNodeStyle-CssClass class and use jquery to set them...

you could remove the href of link('a') tag attribute to stop post back

$('#ctl00_ContentPlaceHolder1_tvHierarchyView table tr td>a').click(function () {  
      var treeViewData = window["<%=tvHierarchyView.ClientID%>" + "_Data"];        
      if (treeViewData.selectedNodeID.value != "") {      
            var selectedNode=document.getElementById(treeViewData.selectedNodeID.value);    
            var value = selectedNode.href.substring(selectedNode.href.indexOf(",") + 3, selectedNode.href.length - 2);                  
            var text = selectedNode.innerHTML;  
          alert("Text: " + text + "\r\n" + "Value: " + value);  
       } else {  
               alert("No node selected.")  
          }  
              $(this).removeAttr("href");

          ///  ...................... rest of your code

}); ///  End of click function    
}); /// End of document ready function

Here steps explanation:

  1. Get the dev id which contains the tree table by Using inspect element:
  2. Get details from the selected child node.
  3. After taken the details of child node , remove the attribute "href" to avoid post back.
  4. Do whatever functionality you what do with selected node details (eg pass selected value using ajax)
TreeNode tn = new TreeNode();

tn.SelectAction = TreeNodeSelectAction.None; OR tn.SelectAction = TreeNodeSelectAction.Expand;

Both of these will not cause postback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!