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

2 posts, 1 answers
  1. James
    James avatar
    8 posts
    Member since:
    Nov 2011

    Posted 23 May 2012 Link to this post

    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.

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

    Posted 23 May 2012 Link to this post

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