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

onclick not working for child nodes when ExpandMode.WebService is used.

5 Answers 123 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
sonal
Top achievements
Rank 1
sonal asked on 22 Aug 2008, 01:18 PM

Hi, 
    I am using ExpandMode.WebService option to load child nodes dynamically.

Following is the code:
UI -

<telerik:RadTreeView ID="uxRadTreeView" 
                        Runat="server"
   <Nodes>
        <telerik:RadTreeNode runat="server"
                             ExpandMode="WebService"
                             Text="Category1" Value="Category1">
        </telerik:RadTreeNode>
  </Nodes>
<webservicesettings method="GetChildNodes"
           path="SampleService.asmx" />
</telerik:RadTreeView>


WebService Method -

public static RadTreeNodeData[] GetChildNodes(RadTreeNodeData node, object context)
        {
            List<RadTreeNodeData> result = new List<RadTreeNodeData>();

            // add data for child nodes
            for (int i = 0; i < 5; i++)
            {
                RadTreeNodeData nodeData = new RadTreeNodeData();
                nodeData.Text = "child" + node.Value.ToString() + i;
                nodeData.Value = "child" + node.Value.ToString() + i;
                nodeData.Attributes.Add("onclick", "func();");
                
                if (i == 0)
                {
                    //temporarily make first node always expandable
                    nodeData.ExpandMode = TreeNodeExpandMode.WebService;
                }

                result.Add(nodeData);
            }
           
            return result.ToArray();
        }

I am attaching onclick handler to each child node, please refer the green line above.

When i click on the node, onclick handler does not execute. Am i missing something?

I also tried iterating all the child node on onclientnodepopulated handler and attaching the onclick handler there.
still no luck.

I would really appreciate any kind of help.

Thanks
Sonal

5 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 22 Aug 2008, 01:42 PM
Hi sonal,

You need to subscribe to the OnClientNodeClicking or OnClientNodeClicked events.

I hope this helps.

Kind regards,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
sonal
Top achievements
Rank 1
answered on 17 Sep 2008, 08:32 AM

Hi,
    Can't i do something like this?

  nodeData.Attributes.Add("OnClientNodeClicked", "func();");

  When i try above then node does not get expanded.

Thanks
Sonal
0
Veselin Vasilev
Telerik team
answered on 17 Sep 2008, 08:48 AM
Hi sonal,

No, you cannot attach a clicking event to a particular node. You attach that event to the treeview and depending on some conditions you can cancel the OnClientNodeClicking event if you want. In this way you can fire the clicking event for particular nodes only.

Sincerely yours,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
sonal
Top achievements
Rank 1
answered on 17 Sep 2008, 11:53 AM
I can't even add any key value pair to RadTreeNodeData's  Attributes, why is that so?
If  i add anything to attributes, the clicked node does not get expanded.

Thanks
Sonal
0
sonal
Top achievements
Rank 1
answered on 18 Sep 2008, 04:20 AM
Hi,
     Sorry, I figured out the mistake, custom attributes works fine.

Thanks
Sonal
Tags
TreeView
Asked by
sonal
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
sonal
Top achievements
Rank 1
Share this question
or