How to assign NodeClick handler in Code Behind?

2 posts, 0 answers
  1. Marcus
    Marcus avatar
    30 posts
    Member since:
    Feb 2009

    Posted 05 Dec 2013 Link to this post

    Hi There

    I have master/content page with two ContentPlaceHolders: Nav and Main. both Nav and Main contain UserControls, where Nav has a navigation UserControl (RadPanel with RadTreeView) and Main has a RadGrid (kind of obvious, right ;-) ).

    Obviously the objective is to populate the RadGrid with data dependent on the node that is clicked.

    Instead of bubbling up events from the user controls, which I find awkward, I thought I could put the NodeClick Event Handler in the code behind on the content page and assign the event handler in the page load event:

    protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
                ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolderNav");
                RadPanelBar rpb = (RadPanelBar)cph.FindControl("RadPanelBar1");
                RadPanelItem itm = (RadPanelItem)rpb.Items[1];
                UserControl uc = (UserControl)itm.FindControl("Nav");
                RadTreeView rtv = (RadTreeView)uc.FindControl("RadTreeView2");
                rtv.NodeClick += RadTreeView1_NodeClick;

    The code works - when stepping through I can see that the TreeView is found - but the event doesn't fire when clicking on a node (-> a breakpoint in RadTreeView1_NodeClick in the content page is not reached).

    Is what I'm trying to do not possible? Or does this just need to go somewhere else in the page lifecycle (Page_Init?).

    Thx in advance for help and/or pointers!

    Rgds - Marcus.

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

    Posted 05 Dec 2013 Link to this post

    Hi Marcus,

    In order for the NodeClick event to fire, a 'postback' should be made when a Node is clicked. Therefore the PostBack property of Nodes which fire the NodeClick event should be set to True. Please try the following code snippet which works fine at my end and you can also write the code inside the Page_Init event.

    protected void Page_Load(object sender, EventArgs e)
        UserControl user = (UserControl)this.Master.FindControl("WebUserControl1");
        RadPanelBar panel = (RadPanelBar)user.FindControl("RadPanelBar1");
        RadTreeView tree = (RadTreeView)panel.FindItemByText("Item1").FindControl("RadTreeView2");
        tree.NodeClick += new RadTreeViewEventHandler(tree_NodeClick);
    void tree_NodeClick(object sender, RadTreeNodeEventArgs e)
        Response.Write("Fired" + e.Node.Text);

    Let me know if you have any concern.

  3. DevCraft R3 2016 release webinar banner
Back to Top