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

Dynamically creating a RadTreeView Error

6 Answers 187 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
CBARS
Top achievements
Rank 2
CBARS asked on 29 Oct 2008, 06:37 AM
Hi

When I try to dynamically add a RadTreeView to a page, VS returns a JScript error, inside the Telerik.Web.UI.RadTreeView._preInitialize function.

This is my page :

<body> 
    <form id="form1" runat="server"
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
    </div> 
    </form> 
</body> 

my code-behind :

namespace DynamicTreeViewTest 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            Telerik.Web.UI.RadTreeView testtree = new Telerik.Web.UI.RadTreeView(); 
            testtree.ID = "testtree"
            Telerik.Web.UI.RadTreeNode testnode = new Telerik.Web.UI.RadTreeNode("Node 1"); 
            testtree.Nodes.Add(testnode); 
            this.Controls.Add(testtree); 
        } 
    } 

VS throws a null exception error, but the text is :

Microsoft JScript runtime error: 'null' is null or not an object

This is the code where the exception is thrown (line indicated) :

Telerik.Web.UI.RadTreeView._preInitialize=function(_219,_21a){ 
var _21b=$get(_219); 
_21b.scrollTop=_21a; <-- Error
if(Telerik.Web.UI.RadTreeView._isRtl(_21b)){ 
Telerik.Web.UI.RadTreeView._initializeRtl(_21b); 
}; 

I've downloaded the new version of the controls (2008 Q2 1001), but they cause the same error.









6 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 30 Oct 2008, 08:23 AM
Hello,

RadTreeView should be nested inside form element, so you have to add it like this:

form1.Controls.Add(testtree);  

Regards,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kailash
Top achievements
Rank 1
answered on 08 Jan 2009, 10:17 AM
Well i have same kind of problem but in my case i am not adding Telerik Tree View control dynamically to page.
I have an User Control and this UC contains a Telerik Tree View control that is nested inside a Panel. Now i put this UC in a webpartzone.
Everything work fine but when i close this webpart i got this error at runtime.
Please suggest.
VS throws a null exception error, but the text is :

Microsoft JScript runtime error: 'null' is null or not an object

This is the code where the exception is thrown (line indicated) :

Telerik.Web.UI.RadTreeView._preInitialize=function(_219,_21a){ 
var _21b=$get(_219); 
_21b.scrollTop=_21a; <-- Error
if(Telerik.Web.UI.RadTreeView._isRtl(_21b)){ 
Telerik.Web.UI.RadTreeView._initializeRtl(_21b); 
}; 

0
Christian
Top achievements
Rank 1
answered on 24 Feb 2009, 01:31 PM
Hi,
I get the same Error.

In my case, I have 5 different Ajaxsettings in the radajaxmanager.
One of them is updating  the tree, for which the error occurs in the preinit step.
But the Error only occurs if i set the tree to visible = false AND call an different async postback, which has nothing to do with the tree.
the different asnyc postback updates an panel which hasn't any connection to the tree.
In Fiddler I see at the async Postback, that a startupscript for the tree will be processed:

scriptStartupBlock|ScriptContentNoTags|Telerik.Web.UI.RadTreeView._preInitialize("rtvLib","0");|1661

any Idea?
0
Veselin Vasilev
Telerik team
answered on 24 Feb 2009, 02:12 PM
Hi guys,

Since it is hardly for us to reproduce the problem, can you please open support tickets and attach a sample working project there? We will debug it locally and give you more adequate answers.

Thanks

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Christian
Top achievements
Rank 1
answered on 24 Feb 2009, 02:17 PM
Ok,
I found a solution for my problem. It was not enough to set the panel which is surounding the tree to visible=false. I had to set the visibility of the tree also to false. No it works.
0
James
Top achievements
Rank 1
answered on 06 May 2010, 09:16 PM
My issue is similiar to Christian's but his suggestion isn't working for me. 

In my scenario I have a div that is set to visible = false by default in the aspx code with the tree control inside the div. 

 

 

 

<div id="divTree" runat="server" visible="false" enableviewstate="false">  
    <telerik:RadTreeView  ...  </telerik:RadTreeView> 
</div> 

On post-back, in the pageload, I would set visible = true on the div if certain conditions were met.  I would only get the error if I had the tree visible, went to another page, clicked the back button on the browser, and did a post-back to show the tree again.

Other factors: 
  This div is in a User Control
  The page uses a master page
  The div is in a MuliPage control
  I'm using an ajax manager/proxy to perform the post back
  I'm using RadControls for ASP.NET AJAX Q1 2010 SP1

Tags
TreeView
Asked by
CBARS
Top achievements
Rank 2
Answers by
Yana
Telerik team
Kailash
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Veselin Vasilev
Telerik team
James
Top achievements
Rank 1
Share this question
or