+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Assign an event created on the fly RadTreeView

Assign an event created on the fly RadTreeView

6 posts, 0 answered
  1. Jorge Gutiérrez
    Jorge Gutiérrez avatar
    2 posts
    Registered:
    10 May 2010
    10 May 2010
    Link to this post
    Hello friends, I'm new to telerik and I presented the following problem. I am creating a radtreeview runtime, while I am creating the event NodeClick, but when you run it ignores the event. I leave this example:


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM MenuTabla",  ConfigurationManager.ConnectionStrings["myERPConnectionString1"].ConnectionString);
                DataSet links = new DataSet();
                adapter.Fill(links);
                
                radMenuTree2.ID = "radMenuTreeDemo";
                radMenuTree2.Width = Unit.Percentage(100);
                radMenuTree2.DataTextField = "Titulo";
                radMenuTree2.DataFieldID = "idMenu";
                radMenuTree2.DataFieldParentID = "idPadre";
                radMenuTree2.DataSource = links;

                radMenuTree2.DataBind();

                SuperiorRadPane.Controls.Add(radMenuTree2);
                radMenuTree2.NodeClick += new RadTreeViewEventHandler(RadTreeView1_NodeClick1);
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(radMenuTree2, RadTextBox1);            
            }        
        }   

        public void RadTreeView1_NodeClick1(object sender, RadTreeNodeEventArgs e) {        
            RadTextBox1.Text = "YES";
        }
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 May 2010
    Link to this post
    Hello Jorge Gutiérrez,

    Possible reasons for this behavior are

    1. The IsPostBack is true
    2.  The PostBack property of Nodes is set to False. 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.
    3. The Nodes are marked with NavigateUrl - if the NavigateUrl property is set, clicking a Node will cause another page to be opened either in a new or the same window. Hence, the NodeClick event will not fire as there has been a page redirection.


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Jorge Gutiérrez
    Jorge Gutiérrez avatar
    2 posts
    Registered:
    10 May 2010
    11 May 2010
    Link to this post
    Hello Ivan, thanks for response.

    Add this line to assign the values you suggested, but still did not work:

    radMenuTree2.NodeDataBound += new Telerik.Web.UI.RadTreeViewEventHandler(RadTreeView1_DataBound1);

        void RadTreeView1_DataBound1(object sender, RadTreeNodeEventArgs e) {
            e.Node.PostBack = true;
            e.Node.NavigateUrl = "";
        }

    Thanks.
    Jorge Gutiérrez :(
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 May 2010
    Link to this post
    Hi Jorge Gutiérrez,

    Below is a sample code that I use at my end without problems

    protected void Page_Load(object sender, EventArgs e)
       {
               var manager = new CmsManager();
               RadTreeView rtv = new RadTreeView();
               Controls.Add(rtv);
               rtv.DataSource = manager.GetPages();
               rtv.NodeDataBound += new RadTreeViewEventHandler(rtv_NodeDataBound);
               rtv.DataBind();
               rtv.NodeClick += new RadTreeViewEventHandler(rtv_NodeClick1);
       }
     
       void rtv_NodeDataBound(object sender, RadTreeNodeEventArgs e)
       {
           var page = e.Node.DataItem as CmsPageContent;
           e.Node.Text = page.MenuName;
       }
     
     
       public void rtv_NodeClick1(object sender, RadTreeNodeEventArgs e)
       {
           RadTextBox1.Text = "YES";
       }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. erato
    erato avatar
    1 posts
    Registered:
    28 Feb 2007
    23 Aug 2010
    Link to this post
    I have the same problem.  Do not have any of the properties set for Postaback.  I have checkboxes on.  I found that when I click on a checkbox, the OnClientNodeClicked event is not fired, but when I click on the node text, it does.

    <telerik:RadTreeView ID="RadTreeView1" runat="server" Width="100%" Height="500"
               PersistLoadOnDemandNodes="False" LoadingStatusPosition="BelowNodeText"            
              OnClientNodeCollapsed="nodeCollapsed" OnClientNodeClicked="nodeClicked" 
              CheckBoxes="true"
              OnClientNodeChecked="clientNodeChecked"
              OnClientNodePopulated="onClientNodePopulated"
              OnClientNodePopulating="onClientNodePopulating">
              <ExpandAnimation Type="none" />
              <Nodes>
                  <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Affil" 
                      Value="1" >
                  </telerik:RadTreeNode>
                  <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Honor" 
                      Value="1">
                  </telerik:RadTreeNode>
                  <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Hosp" 
                      Value="1">
                  </telerik:RadTreeNode>
                  <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="Member" 
                      Value="1">
                  </telerik:RadTreeNode>
                  <telerik:RadTreeNode runat="server" ExpandMode="WebService" Text="SHAEF" 
                      Value="1">
                  </telerik:RadTreeNode>
              </Nodes>
              <CollapseAnimation Type="none" />
              <WebServiceSettings Path="NodeWebService.asmx" Method="GetNodes"  />
          </telerik:RadTreeView>
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    23 Aug 2010
    Link to this post
    Hi erato,

    I do no believe that this is the same problem, since the event that is fired when you click on  a checkbox is OnClientNodeChecking and in your code you have not subscribed for this event.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
6 posts, 0 answered