This is a migrated thread and some comments may be shown as answers.

OnClick event for particular nodes

3 Answers 353 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jason Peetsma
Top achievements
Rank 1
Jason Peetsma asked on 26 May 2008, 06:09 PM
hi,
       I have lots of nodes in my tree. I want to integrate OnClick event such a way that when i click on particular node(node.Category=="Special") then raise the serverSide OnClick ONLY.
       What is the best way to do this. Obviously, i can filter it in the OnClick event but i do not want to do a postback if the node is not "Special". As i have big tree and only few nodes are "special". Thanks,

Regards,

Brendanwood Dev Team

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Milushev
Telerik team
answered on 27 May 2008, 06:25 AM
Hello,

You can handle the OnClientNodeClicking event and check if the node is "Special". If you cancel the client-side NodeClicking event, the TreeView won't postback. Here is a sample snippet:

        <script type="text/javascript"
        function nodeClicking(sender, args) 
        { 
            if(args.get_node().get_category() != "Special") 
            { 
                args.set_cancel(true); 
                args.get_node().set_selected(true); 
            } 
        } 
        </script> 
         
        <telerik:RadTreeView runat="server" ID="RadTreeView1" OnNodeClick="RadTreeView1_NodeClick" OnClientNodeClicking="nodeClicking"
            <Nodes> 
                <telerik:RadTreeNode Text="Node"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode Text="Node"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode Text="Node" Category="Special"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode Text="Node"
                </telerik:RadTreeNode>                 
            </Nodes> 
        </telerik:RadTreeView> 
 

Canceling the NodeClicking event also prevents selection, so we preserve the default behavior by calling set_selected(true) after we cancel the event.

Kind regards,
Dimitar Milushev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
chummy
Top achievements
Rank 1
answered on 31 May 2008, 09:24 AM
content of this function cant be modified???????
when i modify it, it doesnt work.!!!!!!!!
what are sender and args???( u didnt set them in call this function!  (OnClientNodeClicking="nodeClicking)   !!!!)

  function nodeClicking(sender, args) 
        { 
            if(args.get_node().get_category() != "Special") 
            { 
                args.set_cancel(true); 
                args.get_node().set_selected(true); 
            } 
        } 
0
Atanas Korchev
Telerik team
answered on 02 Jun 2008, 07:09 AM
Hi chummy,

Please check this help article which discusses client-side events. The sender and args arguments are passed by the code which invokes the client-side event.
Another possible solution is to set the PostBack server property to false for nodes which should not postback.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Jason Peetsma
Top achievements
Rank 1
Answers by
Dimitar Milushev
Telerik team
chummy
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or