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

RadTreeView $find("<%= RadTreeView1.ClientID %>") returns null

1 Answer 134 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 23 May 2012, 12:25 PM
Hello,

I am using RadTreeView in my ASP.Net WebPart however while access the same control from client side I am getting null for $find().

I am loading the RadTreeView from class which inherits the ASP.Net WebPart class as follows:
protected override void CreateChildControls()
        {
RadTreeView treeview = new RadTreeView() { ID = "RadTreeView", Width = new System.Web.UI.WebControls.Unit(285),
           Height = new System.Web.UI.WebControls.Unit(290),
           CheckBoxes = true
                                                                        };
                    treeview.Nodes.Add(new RadTreeNode("Test"));
                    Controls.Add(treeview);
base.CreateChildControls();           
        }

I am trying to use get the same control from client side from javascript file as follows:
function pageLoad() {
checkMain();
}
function checkMain() {
var tree = $find("<%= RadTreeView1.ClientID %>");
alert(tree);
}


I am getting tree as null, I have went throught all the documentation provided however not sure what missing.

The control render in page as below:
<div style="overflow:auto;height:290px;width:285px;" class="RadTreeView RadTreeView_Default" id="ctl00_m_g_105ccf0c_7bb3_4553_b184_03f24f749c13_RadTreeView">
                        <ul class="rtUL rtLines">
                            <li class="rtLI rtFirst rtLast"><div class="rtTop">
                                <span class="rtSp"></span><input type="checkbox" class="rtChk"><span class="rtIn">Test</span>
                            </div></li>
                        </ul><input type="hidden" name="ctl00_m_g_105ccf0c_7bb3_4553_b184_03f24f749c13_RadTreeView_ClientState" id="ctl00_m_g_105ccf0c_7bb3_4553_b184_03f24f749c13_RadTreeView_ClientState" autocomplete="off" value="{"expandedNodes":[],"collapsedNodes":[],"logEntries":[],"selectedNodes":[],"checkedNodes":[],"scrollPosition":0}">
                    </div>

Please let me know your thoughts.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 May 2012, 02:11 PM
Hello James,

As far as I know, a dynamically created control cannot be accessed from client side using $find method. One suggestion is you can attach the OnClientLoad event and access it using sender argument.
C#:
RadTreeView treeview = new RadTreeView() { ID = "RadTreeView", Width = new System.Web.UI.WebControls.Unit(285),
  Height = new System.Web.UI.WebControls.Unit(290),
 CheckBoxes = true
 treeview.Nodes.Add(new RadTreeNode("Test"));
    treeview.OnClientLoad = "checkMain";
 Controls.Add(treeview);
JS:
function checkMain(sender, args) {
var tree=sender;
alert(tree);
}

Thanks,
Shinu.
Tags
TreeView
Asked by
James
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or