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

Object Reference not set Problem with Treeview within WebUserControl

5 Answers 236 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 09 May 2008, 03:44 AM
Hello,
I am playing with the treeview control and trying to get it to load on demand with a webservice, (Which I have working)

however, I am now trying to capture the onNodeClick server side event.  Upin Clicking a node, I receive an "Object reference not set to an instance of an object." Error with the following stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.ControlItem.LoadFromDictionary(IDictionary`2 dictionary) +165
   Telerik.Web.UI.NavigationItem.LoadFromDictionary(IDictionary`2 dictionary) +31
   Telerik.Web.UI.RadTreeNode.LoadFromDictionary(IDictionary`2 dictionary) +32
   Telerik.Web.UI.ClientStateLogPlayer.Insert(ClientStateLogEntry entry) +179
   Telerik.Web.UI.ClientStateLogPlayer.Play(ClientStateLogEntry entry) +65
   Telerik.Web.UI.ClientStateLogPlayer.Play(IEnumerable`1 clientStateLogEntry) +94
   Telerik.Web.UI.RadTreeView.LoadLogEntries(TreeViewClientState clientState) +78
   Telerik.Web.UI.RadTreeView.LoadClientState(TreeViewClientState clientState) +47
   Telerik.Web.UI.RadTreeView.LoadPostData(String postDataKey, NameValueCollection postCollection) +141
   Telerik.Web.UI.RadDataBoundControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +36
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +661
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1194


The treeview is contained in a WebUserControl.  Has anyone else seen this problem before? 
I had this working with the ASP.Net treeview, but it's too slow, so I want to get the telerik control working.

5 Answers, 1 is accepted

Sort by
0
Lance
Top achievements
Rank 1
answered on 09 May 2008, 01:51 PM
Here is some code that I should have posted earlier...

ASPX File:

<%

@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<

telerik:RadTreeView ID="RadTreeView1" Runat="server"

Skin="Office2007"

OnClientNodePopulating='<%# ClientTreeID & "_nodePopulating"%>'

>

<CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation>

<ExpandAnimation Duration="100"></ExpandAnimation>

</

telerik:RadTreeView>

<

script type="text/javascript">

function <%# ClientTreeID & "_nodePopulating"%>(sender, eventArgs)

{

var node = eventArgs.get_node();

var context = eventArgs.get_context();

context[

"CategoryID"] = node.get_value();

context[

"DisplayNewCategory"] = "<%# DisplayNewCategory %>"

context[

"NewCategoryText"] = "<%# NewCategoryText %>"

context[

"OverRideNodeClick"] = "<%# OverRideNodeClick %>"

}

</

script>

.VB file event handler:

Protected Sub RadTreeView1_NodeClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeClick

Dim tv As RadTreeView = sender

If e.Node.Text = NewCategoryText Then

RaiseEvent NewCategorySelected(e.Node.Value)

Else

RaiseEvent CategorySelected(e.Node.Value, e.Node.Text)

End If

End Sub

0
Lance
Top achievements
Rank 1
answered on 10 May 2008, 01:15 AM
A bit more info if anyone is looking.

I added a PersistLoadOnDemandNodes="true" to the control, but still no dice.

Am I not able to get the NodeClick event on the server for load on demand nodes?

Lance
0
Lance
Top achievements
Rank 1
answered on 10 May 2008, 02:13 PM
Ok, I never did get this to work with the web service calls, but I switched to ServerSideCallback, and it works like I thought it should. 
0
Veselin Vasilev
Telerik team
answered on 12 May 2008, 08:19 AM
Hello Lance,

Can you isolate the problem in a small and running project and send it to us in a new support thread please?

Thanks

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Christian
Top achievements
Rank 1
answered on 18 Aug 2008, 09:20 AM
Hi Lance,

I had a similar problem and i found that my problem was in the following code in my webservice method:

dataNode.Attributes.Add ( "LocationTypeID", location.ID);

location.ID was an integer value and this raised the exception. When i used this:

dataNode.Attributes.Add ( "LocationTypeID", location.ID.ToString());

Everything worked. I don't know if this helps you out but it could give you a pointer on where the bug resides.

Best Regards,
Christian

Tags
TreeView
Asked by
Lance
Top achievements
Rank 1
Answers by
Lance
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Christian
Top achievements
Rank 1
Share this question
or