Unable to find a BaseDataBoundControl derived control in the

Posted by Community Admin on 04-Aug-2018 18:47

Unable to find a BaseDataBoundControl derived control in the template

All Replies

Posted by Community Admin on 08-Jul-2013 00:00

Attempting to create a custom navigation that behaves in the following manner:

If the page has children, display the current page and its children.
If the page has no children, display the current page's parent and the current page's siblings.

Code:

01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using System.Web.UI;
06.using System.Web.UI.WebControls;
07.using Telerik.Sitefinity.Modules.Pages;
08.using Telerik.Sitefinity.Web;
09. 
10.namespace SitefinityWebApp.Templates
11.
12.    public partial class BREINavigation : System.Web.UI.UserControl
13.    
14.        public BaseDataBoundControl control get; set;
15. 
16.        protected void Page_Load(object sender, EventArgs e)
17.        
18. 
19.            PageManager manager = PageManager.GetManager();
20. 
21.            PageSiteNode currentNode = SiteMapBase.GetActualCurrentNode();
22. 
23.            PageSiteNode parentNode;
24.            List<PageSiteNode> childNodes = new List<PageSiteNode>();
25. 
26.            // Figure out if node has children
27.            if (currentNode.HasChildNodes)
28.            
29.                parentNode = currentNode;
30. 
31.                foreach (PageSiteNode cnode in currentNode.ChildNodes)
32.                    if (cnode.ShowInNavigation)
33.                    
34.                        childNodes.Add(cnode);
35.                    
36.                
37. 
38.            
39.            else
40.            
41. 
42.                if (currentNode.ParentNode != null)
43.                
44.                    parentNode = currentNode.ParentNode as PageSiteNode;
45.                 else
46.                    parentNode = currentNode;
47.                
48. 
49.                if (parentNode.HasChildNodes)
50.                
51.                    foreach (PageSiteNode cnode in parentNode.ChildNodes)
52.                    
53.                        if (cnode.ShowInNavigation)
54.                        
55.                            childNodes.Add(cnode);
56.                        
57.                    
58.                
59. 
60.            
61. 
62.            String parentHTML = "";
63.            String childHTML = "";
64. 
65.            parentHTML = "<li class=\"rtsLI rtsFirst\"><a class=\"rtsLink rtsRoot\" href=\"" + parentNode.Url + "\"><span class=\"rtsOut\"><span class=\"rtsIn\"><span class=\"rtsTxt\">" + parentNode.UrlName + "</span></span></span></a></li>";
66. 
67.            int counter = 0;
68. 
69.            if (childNodes.Count() > 0)        
70.            
71. 
72.                childNodes.ForEach(node =>
73.                
74.                    counter += 1;
75. 
76.                    if (childNodes.Count() == counter)
77.                    
78.                        childHTML += "<li class=\"rtsLI rtsLast\"><a class=\"rtsLink\" href=\"" + node.Url + "\"><span class=\"rtsOut\"><span class=\"rtsIn\"><span class=\"rtsTxt\">" + node.UrlName + "</span></span></span></a></li>";
79.                    
80.                    else
81.                    
82.                        childHTML += "<li class=\"rtsLI\"><a class=\"rtsLink\" href=\"" + node.Url + "\"><span class=\"rtsOut\"><span class=\"rtsIn\"><span class=\"rtsTxt\">" + node.UrlName + "</span></span></span></a></li>";                  
83.                    
84.                );
85.                 
86.            
87. 
88.            parentLiteral.Text = parentHTML;
89.            childLiteral.Text = childHTML;
90. 
91.        
92.    
93.

and

1.<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BREINavigation.ascx.cs" Inherits="SitefinityWebApp.Templates.BREINavigation" %>
2. 
3.<div class="rtsLevel rtsLevel1">
4.    <ul class="rtsUL">
5.       <asp:Literal ID="parentLiteral" runat="server" />
6.       <asp:Literal ID="childLiteral" runat="server" />
7.    </ul>
8.</div>

I realize there is probably a hundred different ways I could write this, and there's probably a better way I could write this, but the answer I am here to gather is to resolve an issue.

I am getting the following error message:
"Unable to find a BaseDataBoundControl derived control in the template"

This message displays when I drag a navigation widget onto the page and set the template to be my Navigation template.

Here's some screenshots of how I registered the widget (just in case that was wrong):

dl.dropboxusercontent.com/.../nav.PNG

dl.dropboxusercontent.com/.../settings.PNG

I'm not a guru on ASP.NET so even if this is a silly mistake or a simple fix, I appreciate any help.

Thanks.

Posted by Community Admin on 09-Jul-2013 00:00

Okay, I figured out that my implementation method was a bit wrong. I was confused on what adding the navigation widget to the toolbox actually did, and I see it in the toolbox under the existing navigation items. 

However, when I drag it into the page, I get the following error:

"Object reference not set to an instance of an object"

I'm a bit familiar with this type of error message. It means I'm trying to reference something that isn't correctly set or exists. Problem is, I can't figure out what. 

Any ideas?

Posted by Community Admin on 09-Jul-2013 00:00

Here's the stack trace:

Server Error in '/' Application.Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
SitefinityWebApp.Templates.BREINavigation.Page_Load(Object sender, EventArgs e) +1636
System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034

Posted by Community Admin on 09-Jul-2013 00:00

Rubber duck method!

I figured out that my toolbox settings were incorrect. The CLR path was supposed to be the virtual path to the actual file on the file system, not the namespace of the widget.

This thread is closed