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

Problem with RadTreeView in RadComboBox, multiple controls causing postback

11 Answers 272 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Magnus Bilock
Top achievements
Rank 1
Magnus Bilock asked on 22 Oct 2009, 12:04 PM
I've placed a RadTreeView in a RadComboBox as described in the tutorials. In order to use the ComboBox multiple times on a page, I've placed the controls in a Asp.Net UserControl, and implements the usercontrol in a RadTabStrip. It works perfectly with just one usercontrol, and there is no full postback when the users selects nodes from the tree.

But when I add more than one usercontrol in the tabstrip, a full postback occurs when I select a node from the new tree. There is a full postback every second time. So after a full postback, it works as intended the next time a node is clicked. After that, a full postback occurs again. The first usercontrols works as intended.

I suspect that there's some kind of naming conflict since all trees inside the comboboxes <ItemTemplate> recieves the same ID's, rtvCompanyUserOrganization. Is there any known workaround for this?

Partial code from the usercontrol:

<telerik:RadComboBox ID="rcbCompanyOrganization"  runat="server" Height="140px" Width="215px" OnClientDropDownOpened="OnClientDropDownOpenedUserHandler"
        <Items> 
            <telerik:RadComboBoxItem runat="server" /> 
        </Items> 
        <ItemTemplate> 
            <div ID="div1" onclick="StopPropagation(false);"
                <telerik:RadTreeView ID="rtvCompanyUserOrganization" runat="server" Height="136px" Width="213px" 
                    OnClientNodeClicking="nodeUserClicking" OnNodeClick="NodeClick" > 
                    <DataBindings> 
                        <telerik:RadTreeNodeBinding Expanded="True" /> 
                    </DataBindings> 
                </telerik:RadTreeView> 
            </div> 
        </ItemTemplate> 
    </telerik:RadComboBox> 

11 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 23 Oct 2009, 01:14 PM
Hi Magnus,

You should use unique names for the javascript functions as it's explained here.

Best regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Magnus Bilock
Top achievements
Rank 1
answered on 23 Oct 2009, 03:02 PM
Hi and thanks for your suggestion. Unfortunately it did not solve my full postbacks postback problem. I still get a postback when selecting a node from a usercontrol with a treeview, when there are more than one of the same usercontrols present.

I made a really simple example for you in order to easier explain my problem. It consists of:
Default.aspx: Contains a RadTabStrip with two usercontrols of type TreeViewUserControl. A RadAjaxManager is used in order to prevent full postbacks.
TreeViewUserControl.ascx: Contains a RadComboBox with a RadTreeView inside. The javascriptfunctions are made unique by using the method you suggested.
TreeViewUserControl.ascx.cs: Sets the javascriptfunctions and Adds two nodes to the treeview. The method NodeClick handles the click event caused by selecting a node in the tree.

Below are the code for the files. It should just be to copy->paste and run.

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register Src="~/TreeViewUserControl.ascx" TagPrefix="ts" TagName="test" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <div> 
        <telerik:RadScriptManager ID="ScriptManager1" runat="server" />     
        <telerik:RadAjaxManager runat="server" ID="radAjaxManager"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadTabStrip1"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadTabStrip1"/> 
                        <telerik:AjaxUpdatedControl ControlID="RadMultiPage1"/> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
         
         
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" Skin="Vista" MultiPageID="RadMultiPage1"
            <Tabs> 
                <telerik:RadTab runat="server" Text="RadTabStrip"
                </telerik:RadTab> 
            </Tabs> 
       </telerik:RadTabStrip> 
       <telerik:RadMultiPage id="RadMultiPage1" runat="server" SelectedIndex="0" Width="400"
          <telerik:RadPageView id="Pageview1" runat="server"
              <ts:test ID="tst1" runat="server" /> 
              <ts:test ID="tst2" runat="server" /> 
          </telerik:RadPageView> 
    </telerik:RadMultiPage>  
    </div> 
    </form> 
</body> 
</html> 
 

TreeViewUserControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TreeViewUserControl.ascx.cs" Inherits="TreeViewUserControl" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<telerik:RadAjaxManagerProxy ID="radProxyOrganizationDropDown" runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="rtvCompanyUserOrganization"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="rtvCompanyUserOrganization" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 
 
<telerik:RadScriptBlock ID="radScriptBlockOrganizationDropDown" runat="server"
    <script type="text/javascript"
        function nodeUserClicking_<%= ClientID %>(sender, args) { 
            var comboBox = $find("<%= rcbCompanyOrganization.ClientID %>"); 
            var node = args.get_node() 
            comboBox.set_text(node.get_text()); 
 
 
            comboBox.trackChanges(); 
            comboBox.get_items().getItem(0).set_value(node.get_text()); 
            comboBox.commitChanges(); 
 
            comboBox.hideDropDown(); 
        } 
        function OnClientDropDownOpenedUserHandler_<%= ClientID %>(sender, eventArgs) { 
            var tree = sender.get_items().getItem(0).findControl("rtvCompanyUserOrganization"); 
            var selectedNode = tree.get_selectedNode(); 
            if (selectedNode) { 
                selectedNode.scrollIntoView(); 
            } 
        } 
    </script> 
</telerik:RadScriptBlock> 
     
<div style="float: left; width: 224px;"
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"  
        HorizontalAlign="NotSet">    
    <telerik:RadComboBox ID="rcbCompanyOrganization"  
            Skin="Vista" runat="server" Height="140px" Width="215px" 
        EmptyMessage="Choose a user"
        <Items> 
            <telerik:RadComboBoxItem runat="server"  
                meta:resourcekey="RadComboBoxItemResource1"  /> 
        </Items> 
        <ItemTemplate> 
                <telerik:RadTreeView ID="rtvCompanyUserOrganization" runat="server" Height="136px" Width="213px"  
                    EnableEmbeddedSkins="False"  
                    OnNodeClick="NodeClick" Skin="Vista"
                    <DataBindings> 
                        <telerik:RadTreeNodeBinding Expanded="True" /> 
                    </DataBindings> 
                </telerik:RadTreeView> 
        </ItemTemplate> 
    </telerik:RadComboBox> 
     
    </telerik:RadAjaxPanel> 
</div> 
 
 

TreeViewUserControl.ascx.cs:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Telerik.Web.UI; 
 
public partial class TreeViewUserControl : System.Web.UI.UserControl 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        rcbCompanyOrganization.OnClientDropDownOpened = "OnClientDropDownOpenedUserHandler_" + this.ClientID; 
        RadTreeView rtvCompanyOrganization = (RadTreeView)rcbCompanyOrganization.Items[0].FindControl("rtvCompanyUserOrganization"); 
        rtvCompanyOrganization.OnClientNodeClicking = "nodeUserClicking_" + this.ClientID; 
        rtvCompanyOrganization.Nodes.Clear(); 
        rtvCompanyOrganization.Nodes.Add(new RadTreeNode("Node""Node")); 
        rtvCompanyOrganization.Nodes.Add(new RadTreeNode("Node2""Node2")); 
    } 
 
    protected void NodeClick(object sender, RadTreeNodeEventArgs e) 
    { 
        RadTreeNode clickedNode = e.Node; 
        this.rcbCompanyOrganization.EmptyMessage = clickedNode.Text; 
    } 
 

By running the above you should get two dropdownlists. Selecting a node from the first will not cause a full postback. Selecting a node from the second will cause a full postback.

Any help regarding this problem would be highly appreciated. I'm totally stuck on it.

Best regards
/Magnus Bilock
0
Accepted
Yana
Telerik team
answered on 29 Oct 2009, 01:47 PM
Hi Magnus,

I am sorry for the delayed reply.

I've modified your example in order to fix this issue, please download the attached file and give it a try.

Greetings,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Magnus Bilock
Top achievements
Rank 1
answered on 29 Oct 2009, 02:53 PM

Hi Yana and thanks for your reply.

I tested your example and it works both in the example and in our current development project!

I applied your changes one after the other, and it seems like the row you added in the OnClientNodeClicking javascript-event, comboBox.attachDropDown();, fixed my problem.

Thanks for your time and support, the delay has not been a problem at all.

Best regards
/Magnus Bilock

0
Bader
Top achievements
Rank 1
answered on 21 Nov 2011, 05:16 PM
Hello,

I have a question regarding this issue.

I'm loading the user control dynamiclly using c# code, and your code is not working in this case. 
I want indicate that my Default.aspx page loades dynamiclly too many usercontrols (One of them contains TreeView in RadComboBox) and it has Ajax components. Your attached smaple project is very similar to mine, but, in my case the usercontrol is loaded dynamiclly.

Can you please post a sample code which shows how to solve this problem?

Please, I need your help,

Regards,
Bader
0
Bozhidar
Telerik team
answered on 23 Nov 2011, 01:40 PM
Hello Bader,

I've attached the same sample page, but with the controls added dynamically. Everything seems to work fine. Please take a look at the project. Does it work at your side? if yes - could you please modify it with the exact your configuration, so we can see the problem locally?

Regards,
Bozhidar
the Telerik team
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 their blog feed now
0
Bader
Top achievements
Rank 1
answered on 24 Nov 2011, 07:17 AM
Hello,

Thank you very much for your help, but I still have a problem.
The selected tree view node text/value is not displayed in the combobox (I'm trying to display as the combobox empty message and as a Label text)

Below is my code:

Default.aspx (This page is loading dynamiclly other user controls without problems):
<%@ Page Title="" Language="C#" MasterPageFile="~/Secure/MasterPages/DefaultMasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="GuidesNS.Secure_Mng_Guides_QA_Default" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
 <style type="text/css">
      .hide
        {
            visibility:hidden !important;
        }
   </style>
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="MainPanel">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="MainPanel" LoadingPanelID="MainRadAjaxLoadingPanel" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel ID="MainRadAjaxLoadingPanel" Skin="Vista" runat="server">
</telerik:RadAjaxLoadingPanel>
 
<asp:Panel ID="MainPanel" Width="100%" BorderWidth="0" style="height:auto;" HorizontalAlign="Left" BorderColor="Black" runat="server">
    <asp:Label ID="SelectedItemIDLabel" runat="server" Visible="false" Text=""></asp:Label>
    <asp:Label ID="Label1" runat="server"  Text=""></asp:Label>
    <asp:Panel ID="OperationsPanel" runat="server" Width="100%" HorizontalAlign="Left">
        <telerik:RadMenu ID="OperationsRadMenu" runat="server" Width="100%" OnItemClick="OperationsRadMenu_ItemClick">
            <Items>
                <telerik:RadMenuItem Text="Change Parent" Value="Folder" />
            </Items>
        </telerik:RadMenu>
        <br /><br />
    </asp:Panel>
             
    <asp:Panel ID="MessagePanel" runat="server" Width="95%" style="margin-top:10px; margin-left:20px; margin-right:20px;" HorizontalAlign="Left">
        <asp:Label ID="MessageLabel" runat="server" Font-Bold="true" ForeColor="Red" Font-Italic="true" Font-Size="14pt" Visible="false" Text=""></asp:Label>
    </asp:Panel>
             
    <asp:Panel ID="InernalPanel" runat="server" Width="95%" style="margin:10px;" HorizontalAlign="Left">
    </asp:Panel>
</asp:Panel>
 
</asp:Content>

Default.aspx.cs:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using GuidesNS.CodeHelper;
 
namespace GuidesNS
{
    public partial class Secure_Mng_Guides_QA_Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Control control = null;
                string ctrlname = Page.Request.Params.Get("__EVENTTARGET");
                control = Page.FindControl(ctrlname);
 
                if (control != null)
                {
                    if (control.ID != "OperationsRadMenu" && OperationsRadMenu.SelectedItem != null)
                    {
                        PanelsMng.CleanPanelAndLoadUserControl(Page, InernalPanel, OperationsRadMenu.SelectedItem.Text.Replace(" ", "") + "UserControl.ascx");
                    }
                }
                else
                {
                    if (OperationsRadMenu.SelectedItem != null)
                    {
                        PanelsMng.CleanPanelAndLoadUserControl(Page, InernalPanel, OperationsRadMenu.SelectedItem.Text.Replace(" ", "") + "UserControl.ascx");
                    }
                }
            }
        }
 
        protected void OperationsRadMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            string ssssssss = string.Empty;
            //Hide the message
            Guides.HideMessage(MessageLabel);
 
            if (!e.Item.Text.Replace(" ", "").Equals(string.Empty))
            {
                PanelsMng.CleanPanelAndLoadUserControl(Page, InernalPanel, e.Item.Text.Replace(" ", "") + "UserControl.ascx");
            }
        }
    }
}

ChangeParentUserControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChangeParentUserControl.ascx.cs" Inherits="GuidesNS.Secure_Mng_Guides_MultipleDocs_UserControls_DiffrentDocsPaths_ChangeParentUserControl" %>
  
<telerik:RadAjaxManagerProxy ID="radProxyOrganizationDropDown" runat="server">
   <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="rcbCompanyOrganization">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rcbCompanyOrganization" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>
  
<telerik:RadScriptBlock ID="radScriptBlockOrganizationDropDown" runat="server">
    <script type="text/javascript">
        function nodeUserClicking_<%= ClientID %>(sender, args) {
            var comboBox = $find("<%= rcbCompanyOrganization.ClientID %>");
            comboBox.attachDropDown();
              
            var node = args.get_node()
            comboBox.set_text(node.get_text()); 
  
            comboBox.trackChanges();
            comboBox.get_items().getItem(0).set_value(node.get_text());
            comboBox.commitChanges();
  
            comboBox.hideDropDown();
        }
        function OnClientDropDownOpenedUserHandler_<%= ClientID %>(sender, eventArgs) {
            var tree = sender.get_items().getItem(0).findControl("rtvCompanyUserOrganization");
            var selectedNode = tree.get_selectedNode();
            if (selectedNode) {
                selectedNode.scrollIntoView();
            }
        }
            
        function nodeUserClicked_<%= ClientID %>(sender, args)
        {
            args.get_domEvent().stopPropagation();
        }
             
    </script>
</telerik:RadScriptBlock>
 
<div style="float: left; width: 224px;">
     <asp:SqlDataSource ID="GuidePowerShellSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:GeneralConnectionString %>"
                   SelectCommand="SELECT * FROM [guidesQA] where ([Type] Like '%Folder%') order by [Type],[Title] "></asp:SqlDataSource>
                      
    <telerik:RadComboBox ID="rcbCompanyOrganization" 
            Skin="Vista" runat="server" Height="140px" Width="215px"
        EmptyMessage="Choose a user">
        <Items>
            <telerik:RadComboBoxItem runat="server" 
                meta:resourcekey="RadComboBoxItemResource1"  />
        </Items>
        <ItemTemplate>
                <telerik:RadTreeView ID="rtvCompanyUserOrganization" runat="server" DataValueField="SerID" OnNodeClick="NodeClick"
                DataSourceID="GuidePowerShellSqlDataSource" DataFieldParentID="ParentID" DataFieldID="SerID" DataTextField="Title" >
                <DataBindings>
                    <telerik:RadTreeNodeBinding Depth="0" Expanded="true" />
                </DataBindings>
                     
            </telerik:RadTreeView>
        </ItemTemplate>
    </telerik:RadComboBox>
    <br />
 
    <asp:Label ID="ResultLabel" runat="server" Text=""></asp:Label>
     
    <br /><br />
</div>

ChangeParentUserControl.ascx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using GuidesNS.CodeHelper;
 
namespace GuidesNS
{
    public partial class Secure_Mng_Guides_MultipleDocs_UserControls_DiffrentDocsPaths_ChangeParentUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rcbCompanyOrganization.OnClientDropDownOpened = "OnClientDropDownOpenedUserHandler_" + this.ClientID;
                RadTreeView rtvCompanyOrganization = (RadTreeView)rcbCompanyOrganization.Items[0].FindControl("rtvCompanyUserOrganization");
                rtvCompanyOrganization.OnClientNodeClicking = "nodeUserClicking_" + this.ClientID;
                rtvCompanyOrganization.OnClientNodeClicked = "nodeUserClicked_" + this.ClientID;
                rtvCompanyOrganization.Nodes.Clear();
 
                rtvCompanyOrganization.DataSource = GetDataFromDB.GetDataTable("SELECT * FROM [guidesQA] where ([Type] Like '%Folder%') order by [Type],[Title]");
                rtvCompanyOrganization.DataBind();
            }
        }
 
        protected void NodeClick(object sender, RadTreeNodeEventArgs e)
        {
            RadTreeNode clickedNode = e.Node;
            rcbCompanyOrganization.EmptyMessage = clickedNode.Text;
            ResultLabel.Text = clickedNode.Text;
        }
    }
}

Note: the mehod "ChangePanelControlsVisibilty" removes all controls in a panel control. 

Attached a screen-shot of this page.

Please, I need you help in order to solve this problem.

Regards,
Bader
0
Bozhidar
Telerik team
answered on 24 Nov 2011, 03:45 PM
Hello Bader,

You seem to be loading the controls with the function PanelsMng.CleanPanelAndLoadUserControl(), but I can't find it in your code. Please send the code of the function and where it is defined, so that I can run the page and reproduce your problem.

Best wishes,
Bozhidar
the Telerik team
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 their blog feed now
0
Bader
Top achievements
Rank 1
answered on 24 Nov 2011, 04:38 PM
Hello,

Thank you for your reply,
The code is defined in an external class. The required code is below:

public static void ClearPanel(System.Web.UI.WebControls.Panel panel)
        {
            panel.Controls.Clear();
        }
 
        public static UserControl CleanPanelAndLoadUserControl(Page page, System.Web.UI.WebControls.Panel panel, string path)
        {
            ClearPanel(panel);
 
            UserControl userControl = new UserControl();
            userControl = (UserControl)page.LoadControl(path);
            panel.Controls.Clear();
            panel.Controls.Add(userControl);
            return userControl;
        }


Regards,
Bader
0
Kalina
Telerik team
answered on 30 Nov 2011, 10:49 AM
Hi Bader,

Thank you for the code provided – we used it to create a runnable project and we reproduced the issue.

As I understand - you want to load dynamically user control upon a RadMenu item click.
Within this user control you have a RadComboBox with an ItemTemplate where a RadTreeView is nested.
Since you can have multiple instances of this user control on one page - you need unique names for the functions that you use to handle OnClientDropDownOpened, OnClientNodeClicking  and  OnClientNodeClicked events.

While I was inspecting your code - I saw that you have tried to set these names at PageLoad event and using the approach described in this article. Then I saw that you have tried to set the RadComboBox and Label texts by handling the RadTreeView.OnNodeClick server-side event.

I am suggesting you to use the approach described in the article – to add the event handlers in the code behind, but please make this at OnInit event:
protected override void  OnInit(EventArgs e)
{
    base.OnInit(e);
    rcbCompanyOrganization.OnClientDropDownOpened = "OnClientDropDownOpenedUserHandler_" + this.ClientID;
    RadTreeView rtvCompanyOrganization = (RadTreeView)rcbCompanyOrganization.Items[0].FindControl("rtvCompanyUserOrganization");
    rtvCompanyOrganization.OnClientNodeClicking = "nodeUserClicking_" + this.ClientID;
    rtvCompanyOrganization.OnClientNodeClicked = "nodeUserClicked_" + this.ClientID;
         
}

Then you can update the Label text within the OnClientNodeClicking handler in this way:
function nodeUserClicking_<%= ClientID %>(sender, args) {
     
 
    var comboBox = $find("<%= rcbCompanyOrganization.ClientID %>");
    comboBox.attachDropDown();
               
    var node = args.get_node()
    comboBox.set_text(node.get_text());
   
    comboBox.trackChanges();
    comboBox.get_items().getItem(0).set_value(node.get_text());
    comboBox.get_items().getItem(0).set_text(node.get_text());
    comboBox.commitChanges();
   
    comboBox.hideDropDown();
            
    var label = document.getElementById("<%=ResultLabel.ClientID %>");
    label.innerHTML = node.get_text();
 
}

Please find the sample attached, give it a try and let me know if this helps.


Regards,
Kalina
the Telerik team
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 their blog feed now
0
Bader
Top achievements
Rank 1
answered on 30 Jan 2012, 03:58 PM
Hi,

Thank you very much for the sample application, It solved the problem.

I'm using now the RadTreeView in RadComboBox in within the EditForm of RadGrid control.
Below is the usercontrol (EditForm of the RadGrid control).  I tried the it, and It works but with problems.
By selecting any node the ResultLabel displays the selected node text, but by trying to select another node I get a webpage error: Error: Unable to get value of the property 'get_selectedNode': object is null or undefined (Attached screen-shot). and after closing the webpage error, the RadTreeView doesn't displays the nodes anymore.

ascx code:


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SubUserControl.ascx.cs" Inherits="GuidesNS.Secure_Mng_Dev_Menus_SubUserControl" %>
<link rel="stylesheet" type="text/css" href="../../../Design/Style/SecureManagenmentStyle.css" />
 
<asp:Panel ID="SubPanel" runat="server" style="margin:10px;">
    <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
        style="BORDER-COLLAPSE: collapse">
        <tr>
            <td id="Td2" align="<%$ Resources:MngResource, ContentFloat %>" runat="server">
                 
 
                <telerik:RadScriptBlock ID="radScriptBlockOrganizationDropDown" runat="server">
                    <script type="text/javascript">
      
                    function nodeUserClicking_<%= ClientID %>(sender, args) {
     
 
                        var comboBox = $find("<%= rcbCompanyOrganization.ClientID %>");
                        comboBox.attachDropDown();
               
                        var node = args.get_node()
                        comboBox.set_text(node.get_text());
   
                        comboBox.trackChanges();
                        comboBox.get_items().getItem(0).set_value(node.get_text());
                        comboBox.get_items().getItem(0).set_text(node.get_text());
                        comboBox.commitChanges();
   
                        comboBox.hideDropDown();
            
                        var label = document.getElementById("<%=ResultLabel.ClientID %>");
                        label.innerHTML = node.get_text();
 
                    }
                        function OnClientDropDownOpenedUserHandler_<%= ClientID %>(sender, eventArgs) {
                            var tree = sender.get_items().getItem(0).findControl("rtvCompanyUserOrganization");
                            var selectedNode = tree.get_selectedNode();
                            if (selectedNode) {
                                selectedNode.scrollIntoView();
                            }
                        }
             
                        function nodeUserClicked_<%= ClientID %>(sender, args)
                        {
                            args.get_domEvent().stopPropagation();
                        }
             
 
                    </script>
                </telerik:RadScriptBlock>
 
                <telerik:RadComboBox ID="rcbCompanyOrganization"
                    runat="server" Height="140px" Width="215px"
                    EmptyMessage="Choose a user">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" 
                            meta:resourcekey="RadComboBoxItemResource1"  />
                    </Items>
                    <ItemTemplate>
                        <telerik:RadTreeView
                            ID="rtvCompanyUserOrganization" 
                            runat="server" >
                            <Nodes>
                                <telerik:RadTreeNode Text="Root">
                                    <Nodes>
                                        <telerik:RadTreeNode Text="node 1" />
                                        <telerik:RadTreeNode Text="node 2" />
                                        <telerik:RadTreeNode Text="node 3" />
                                        <telerik:RadTreeNode Text="node 4">
                                            <Nodes>
                                                <telerik:RadTreeNode Text="node 4.1" />
                                                <telerik:RadTreeNode Text="node 4.2" />
                                                <telerik:RadTreeNode Text="node 4.3" />
                                                <telerik:RadTreeNode Text="node 4.4" />
                                            </Nodes>
                                        </telerik:RadTreeNode>
                                    </Nodes>
                                </telerik:RadTreeNode>
                            </Nodes>
                            <DataBindings>
                                <telerik:RadTreeNodeBinding Depth="0" Expanded="true" />
                            </DataBindings>
                        </telerik:RadTreeView>
                    </ItemTemplate>
                </telerik:RadComboBox>
                <br />
  
                <asp:Label ID="ResultLabel" runat="server" Text=""></asp:Label>
            </td>
         </tr>
         <tr>
            <td align="<%$ Resources:MngResource, NoContentFloat %>" runat="server" colspan="2">
                <asp:button id="btnUpdate" text="<%$ Resources:TelerikResource, RadGridEditFormUpdateButtonText %>" runat="server" CommandName="Update" Visible='<%# !(DataBinder.Eval( Container, "DataItem") is Telerik.Web.UI.GridInsertionObject) %>'></asp:button>
                    <asp:button id="btnInsert" text="<%$ Resources:TelerikResource, RadGridEditFormInsertButtonText %>" runat="server" CommandName="PerformInsert" Visible='<%# DataBinder.Eval( Container, "DataItem") is Telerik.Web.UI.GridInsertionObject %>'></asp:button>
                      
                    <asp:button id="btnCancel" text="<%$ Resources:TelerikResource, RadGridEditFormCancelButtonText %>" runat="server" causesvalidation="False" commandname="Cancel"></asp:button>
            </td>
        </tr>
    </table>
</asp:Panel>

c#:
using System;
using System.Data;
using Telerik.Web.UI;
using System.Web.UI.WebControls;
using CodeHelper;
namespace GuidesNS
{
public partial class Secure_Mng_Dev_Menus_SubUserControl : System.Web.UI.UserControl
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rcbCompanyOrganization.OnClientDropDownOpened = "OnClientDropDownOpenedUserHandler_" + this.ClientID;
RadTreeView rtvCompanyOrganization = (RadTreeView)rcbCompanyOrganization.Items[0].FindControl("rtvCompanyUserOrganization");
rtvCompanyOrganization.OnClientNodeClicking = "nodeUserClicking_" + this.ClientID;
rtvCompanyOrganization.OnClientNodeClicked = "nodeUserClicked_" + this.ClientID;
}
protected void NodeClick(object sender, RadTreeNodeEventArgs e)
{
RadTreeNode clickedNode = e.Node;
rcbCompanyOrganization.EmptyMessage = clickedNode.Text;
ResultLabel.Text = clickedNode.Text;
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}

Please, I need your help in order to solve the above problem

Regards,
Bader
Tags
TreeView
Asked by
Magnus Bilock
Top achievements
Rank 1
Answers by
Yana
Telerik team
Magnus Bilock
Top achievements
Rank 1
Bader
Top achievements
Rank 1
Bozhidar
Telerik team
Kalina
Telerik team
Share this question
or