collapse - expand When click on Node that have children, without PostBack

5 posts, 1 answers
  1. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 16 Jul 2014 Link to this post

    Hello,

    I am currently working on a project with a RadTreeView.

    I need only when I click on a leaf with no children it do a PostBack.
    When I click on a leaf that has children, it will be performed expand/ collapse - depending on the current mode.
    (If it has been expanded – it will be collapse, if collapse - expand)

    I have a js code, but it’s give me an error every time I click on a node that has children:

    ASPX:
    01.// TreeView_Menu Expand/Colapse When Pressing On Branch Node
    02. function TreeViewExpanCollaps_OnClientNodeClicked(sender, args) {
    03.     var node = args.get_node(),
    04.         $element = $(node.get_element()),
    05.         $selectedNodeElement;
    06. 
    07.     if (node.get_nodes().get_count() > 0) {
    08.         if (!node.get_expanded()) {
    09.             node.expand();
    10.             args.set_cancel(true);
    11.         }
    12.         else {
    13.             node.collapse();
    14.             args.set_cancel(true);
    15.         }
    16.     }
    17. 
    18. 
    19. }
    20.  
    21. <telerik:RadTreeView ID="RadTreeView1" Runat="server" Skin="MetroTouch" OnClientNodeClicked="TreeViewExpanCollaps_OnClientNodeClicked">


    VB.net:
    Protected Sub RadTreeView1_NodeClick(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeClick
            lbl_txt.Text = e.Node.Text
    End Sub


    Errors:
    Uncaught TypeError: undefined is not a function expand_colapse_treeview.aspx:28
    TreeViewExpanCollaps_OnClientNodeClicked expand_colapse_treeview.aspx:28
    (anonymous function) Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6
    Telerik.Web.UI.RadWebControl.raiseEvent Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:951
    c.RadTreeView._raiseEvent Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:5434
    c.RadTreeView._click Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:5385
    Telerik.Web.UI.EventMap._onDomEvent Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:3114
    (anonymous function) Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6
    b
    (The error refers to lines  10 and 14)


    How to solve this problem ?
    I’ll be glad for your help.

    Thanks,

    Daniel.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Jul 2014 in reply to Daniel Link to this post

    Hi Daniel,

    Please do the following modification in your JavaScript which works fine at my end.

    JavaScript:
    function TreeViewExpanCollaps_OnClientNodeClicked(sender, args) {
        var node = args.get_node();
        if (node.get_nodes().get_count() > 0) {
            if (!node.get_expanded()) {
                node.expand();
                args.set_cancel(true);
            }
            else {
                node.collapse();
                args.set_cancel(true);
            }
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 17 Jul 2014 in reply to Shinu Link to this post

    Hey Shinu,

     
    Thank you for the quick response.

    Your code works but it throws the same error as before “ERROR:Uncaught TypeError: undefined is not a function”.

    I Attached video that shows the situation where the error is thrown.
    [RadTreeView Error Video]


    I’ll be glad for a solution without any errors.

     

    Thanks,

    Daniel.
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Jul 2014 in reply to Daniel Link to this post

    Hi Daniel,

    Try to attach the OnClientNodeClicking event which works fine at my end. OnClientNodeClicked event doesn't have args.set_cancel property because of that it was showing this error.

    Thanks,
    Shinu.
  6. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 17 Jul 2014 in reply to Shinu Link to this post

    Hi Shinu,

     
    Thank you for the very quick response!!!

    It's work!

    Thanks,

    Daniel.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017