Element 'ElephantTreeView' is not a known element. This can occur ifthere is a compilation error in

D

Dave

Trying to implement a tree control that I cound on the internet. "I
believe" that I'm doing the right thing but I'm currently getting the
following Error:

Element 'ElephantTreeView' is not a known element. This can occur if
there is a compilation error in the Web site, or the web.config file
is missing.


Can someone please point it out what I might be doing wrong.

Thanks


**************************************
****Control on .Master Page*****
**************************************
<asp:panel ID="Panel1" runat="server" Height="534px" ScrollBars="Auto"
Width="300px">
<aptera:ElephantTreeView ID="MyTreeView" runat="server"
DataServicesID="" />
</asp:panel>


**************************************
********** Web.Config ***********
**************************************
<pages theme="Jacobs" enableEventValidation="false"
viewStateEncryptionMode="Never">
<controls>
<add tagPrefix="aptera" namespace="web.App_Code"/>
</controls>
</pages>


**************************************
************ .CS file **************
**************************************
using System.Web;
using System.Web.UI.WebControls;

namespace web
{
public class ElephantTreeView : TreeView
{
private string GetNodeKey(TreeNode node)
{
return string.Format("{0}_{1}_{2}", this.ID, node.Depth,
node.Text);
}

protected virtual void SaveNodeState(TreeNode node)
{
// determine the node's unique key string
string key = GetNodeKey(node);

// store the node's expansion state
HttpContext.Current.Session[key] = node.Expanded;
}

protected virtual void RestoreNodeState(TreeNode node)
{
object expanded =
HttpContext.Current.Session[GetNodeKey(node)];
if (expanded != null)
{
node.Expanded = (bool)expanded;
}
foreach (TreeNode childNode in node.ChildNodes)
{
RestoreNodeState(childNode);
}
}

protected override void OnDataBound(System.EventArgs e)
{
foreach (TreeNode node in this.Nodes)
{
RestoreNodeState(node);
}

base.OnDataBound(e);
}

protected override void OnTreeNodeExpanded(TreeNodeEventArgs
e)
{
if (Page.IsPostBack)
{
SaveNodeState(e.Node);
}
base.OnTreeNodeExpanded(e);
}

protected override void OnTreeNodeCollapsed(TreeNodeEventArgs
e)
{
// persist the state of the collapsed node
if (Page.IsPostBack)
{
SaveNodeState(e.Node);
}

// go about our other OnTreeNodeCollapsed business
base.OnTreeNodeExpanded(e);
}

protected override void OnLoad(System.EventArgs e)
{
this.EnableClientScript = false;
base.OnLoad(e);
}
}
}
 
D

Dave

Pete,
Thanks for responding and not just kicking back a "You don't belong
here" resonse. I thought I'd removed .App_Code. I've been bouncing
this around with no luck. I corrected it as you pointed out with no
luck. Anything else come to mind? I'll also post under ASPNet.

Thanks

Dave
 
K

kndg

Hi Dave,

As Pete had suggested, ASP.NET newsgroup would serve you better. But as
I try your code, it did compiled just fine (yes, the namespace you set
in web.config have to match your source code namespace). I tried feed it
with test data and it shows correctly (I didn't check the code logic
though...).
Did you actually put the source code file in App_Code folder?
If the above still fail, you may try to compile the source code as
library and put it in the bin folder. You need to add the
assembly="yourassemblyname" attribute to the web.config file.

Regards.
 
D

Dave

Kndg
Ok...you got me on that one. Compile as a Library? Can you elaborate
a little?

Also, in VS 2010 App_Code isn't an option in ASP.Net folders. But
with that said I've tried it in and out of that folder. Should it be
in that folder?

Thanks to everyone that's commented. I did post it in ASP.NET and as
of this morning have not received any help.


Thanks again
 
K

kndg

Kndg
Ok...you got me on that one. Compile as a Library? Can you elaborate
a little?

I don't have VS2010 yet, so here is what I would do in VS2008 (I think
it would mostly the same)

1. Right-click on the solution and choose Add -> New Project
2. Make sure "Web" is selected as the Project Type (left pane), then
choose "ASP.NET Server Control" template (right pane)
3. Give a name to your project and click OK
4. Right-click on your newly created project and choose Add -> Class
5. Name it "ElephantTreeView.cs" and click Add
6. Add your code into this class
7. Right-click on the project and choose Build
8. Switch back to your Web Application project
9. Right-click on it and choose Add Reference
10. On the Projects tab, choose your newly added project
11. Double-click web.config to edit it
12. Under <configuration> -> <system.web> -> <pages> -> <controls>
hierarchy add below statement

<add tagPrefix="aptera" namespace="yourcontrolnamespace"
assembly="yourassemblyname"/>

Notes:
"yourcontrolnamespace" is the name of the namespace defined in
"ElephantTreeView.cs"
"yourassemblyname" is by default is the name of your newly created project

13. Rebuid your solution and see if it works
Also, in VS 2010 App_Code isn't an option in ASP.Net folders. But
with that said I've tried it in and out of that folder. Should it be
in that folder?

Yes, if you didn't choose the above option (dll route), your source code
file must reside in App_Code folder. Just right-click your Web
Application project and choose Add -> New Folder. Rename it to App_Code,
right-click on it and choose Add -> Class. Name it "ElephantTreeView.cs"
and add your code. Modify the web.config to match the namespace on
"ElephantTreeView.cs" class. Rebuild your solution and it should work.

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top