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

OnSelectedNodeChanged

6 Answers 268 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 07 Oct 2013, 10:01 AM
Hi,

I have not found a method for capturing when a selected node changes as the OnSelectedNodeChanged provided by asp:TreeView.
Do you know how to capture this event?
Thank you,
Sonia.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Oct 2013, 11:58 AM
Hi Sonia,

In RadTreeView, OnNodeClick event is used to capture selected node change on server side and OnClientNodeClicked is used to achieve the same via client side. Please check the following help documentations.

NodeClick
OnClientNodeClicked

Thanks,
Shinu.


0
Sonia
Top achievements
Rank 1
answered on 07 Oct 2013, 12:33 PM
OnNodeClick is not fire if the selection is made in code behind, and this is the scenario i need to solve!!

Please, any idea?
0
Kate
Telerik team
answered on 08 Oct 2013, 08:33 AM
Hi Sonia,

I tested the following demo and it seems that the event of the RadTreeView control fires as expected - TreeView - Server-side Events. Please give it a try and let me know how it goes from your side.

Regards,
Kate
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sonia
Top achievements
Rank 1
answered on 08 Oct 2013, 09:30 AM

That demo does not demostrate the scenario i was trying to explain.
See the lines of code below, when i select newTreeNode, OnNodeClick is not fired, however OnSelectedNodeChanged would have fired.

RadTreeNode newTreeNode = new RadTreeNode(name, id);
RadTreeView1.Nodes.Add(newTreeNode);
newTreeNode.Selected = true;
0
Kate
Telerik team
answered on 10 Oct 2013, 02:34 PM
Hi Sonia,

Can you please provide the markup code and the code behind that you are using so I can get a better understanding of the scenario that you currently get? 

Regards,
Kate
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Shinu
Top achievements
Rank 2
answered on 17 Oct 2013, 11:52 AM
Hi Sonia,

Please have a look into the following full code I tried for your scenario.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" OnNodeClick="RadTreeView1_NodeClick">
    <Nodes>
        <telerik:RadTreeNode runat="server" Text="Node 1">
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Node 2">
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Add Node" OnClick="RadButton1_Click">
</telerik:RadButton>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string nodeText = "Node 3";
    string nodeValue = "3";
    RadTreeNode newTreeNode = new RadTreeNode(nodeText, nodeValue);
    RadTreeView1.Nodes.Add(newTreeNode);
    string script = "function f(){nodeClick('" + nodeText + "'); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
}
protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
{
    Response.Write("<script>alert('Node Clicked')</script>");
}

JavaScript:
<script type="text/javascript">
    function nodeClick(arg) {
        var radtreeview = $find('<%=RadTreeView1.ClientID %>');
        radtreeview.findNodeByText(arg).select();
    }
</script>

In the above code after creating the RadNode from sever side, I am calling a script "nodeClick". In the script I am accessing the node which is added from server side and then selecting it which in turn fire the OnNodeClick server side event.

Thanks,
Shinu.
Tags
TreeView
Asked by
Sonia
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sonia
Top achievements
Rank 1
Kate
Telerik team
Share this question
or