OnSelectedNodeChanged

7 posts, 0 answers
  1. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 07 Oct 2013 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Oct 2013 Link to this post

    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.


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 07 Oct 2013 Link to this post

    OnNodeClick is not fire if the selection is made in code behind, and this is the scenario i need to solve!!

    Please, any idea?
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 08 Oct 2013 Link to this post

    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.
  6. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 08 Oct 2013 Link to this post

    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;
  7. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 10 Oct 2013 Link to this post

    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.
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Oct 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017