Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Issue with a custom TreeView derived from the TreeView control

Reply
Thread Tools

Issue with a custom TreeView derived from the TreeView control

 
 
Ionutz
Guest
Posts: n/a
 
      10-22-2005
Hello!
I derived a control from the standard TreeView control of ASP.NET 2.0, which
uses custom tree nodes derived from the TreeNode class.

The problem is that when I set the property PopulateOnDemand = true on a
node of my tree view and try to expand the node, I receive a
System.NullReferenceException with the folowing stack trace:

at System.Web.UI.WebControls.TreeNode.RenderChildNode s(HtmlTextWriter
writer, Int32 depth, Boolean[] isLast, Boolean enabled)
at System.Web.UI.WebControls.TreeView.RaiseCallbackEv ent(String
eventArgument)
at
System.Web.UI.WebControls.TreeView.System.Web.UI.I CallbackEventHandler.RaiseCallbackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


When I don't use the populate on demand feature everything works fine.

Here is a snippet of the code that I wrote:

public class MyTreeView : TreeView
{
...
protected override TreeNode CreateNode()
{
return new MyTreeNode();
}
...
}

public class MyTreeNode : TreeNode
{
public MyTreeNode(string text) : base(text)
{
}
}

Also I handled the event TreeNodePopulate to get my nodes data.

Does anyone encountered this problem and is there a workaround for this ?
I mention that I use VS 2005 beta 2.

Thank you,
 
Reply With Quote
 
 
 
 
markdemich@gmail.com
Guest
Posts: n/a
 
      10-23-2005

Ionutz wrote:
> Hello!
> I derived a control from the standard TreeView control of ASP.NET 2.0, which
> uses custom tree nodes derived from the TreeNode class.
>
> The problem is that when I set the property PopulateOnDemand = true on a
> node of my tree view and try to expand the node, I receive a
> System.NullReferenceException with the folowing stack trace:
>
> at System.Web.UI.WebControls.TreeNode.RenderChildNode s(HtmlTextWriter
> writer, Int32 depth, Boolean[] isLast, Boolean enabled)
> at System.Web.UI.WebControls.TreeView.RaiseCallbackEv ent(String
> eventArgument)
> at
> System.Web.UI.WebControls.TreeView.System.Web.UI.I CallbackEventHandler.RaiseCallbackEvent(String eventArgument)
> at System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>
>
> When I don't use the populate on demand feature everything works fine.
>
> Here is a snippet of the code that I wrote:
>
> public class MyTreeView : TreeView
> {
> ...
> protected override TreeNode CreateNode()
> {
> return new MyTreeNode();
> }
> ...
> }
>
> public class MyTreeNode : TreeNode
> {
> public MyTreeNode(string text) : base(text)
> {
> }
> }
>
> Also I handled the event TreeNodePopulate to get my nodes data.
>
> Does anyone encountered this problem and is there a workaround for this ?
> I mention that I use VS 2005 beta 2.
>
> Thank you,


Sorry, I don't know the answer to your question, maybe if you use
Reflector and check out the framework code it might give you an idea of
what's going on. On another note, I have a question of my own that
maybe you can answer. I was attempting to override the TreeView and
TreeNode controls so I could alter the nodes render method. I was
trying to add columns. Unfortunately, I discovered that that most of
the methods I needed to override were private. Can I as what you're
doing in your custom controls?

Thanks,
Mark

 
Reply With Quote
 
 
 
 
Ionutz
Guest
Posts: n/a
 
      10-23-2005


"" wrote:
>
> Sorry, I don't know the answer to your question, maybe if you use
> Reflector and check out the framework code it might give you an idea of
> what's going on. On another note, I have a question of my own that
> maybe you can answer. I was attempting to override the TreeView and
> TreeNode controls so I could alter the nodes render method. I was
> trying to add columns. Unfortunately, I discovered that that most of
> the methods I needed to override were private. Can I as what you're
> doing in your custom controls?
>
> Thanks,
> Mark
>
>


I found where the problem comes from.
I used the Reflector.NET and I observed the following code for the
CreateNode method:

protected internal virtual TreeNode CreateNode()
{
return new TreeNode(this, false);
}

The problem is that this constructor of TreeNode is declared as internal and
when I create an instance of MyTreeNode I can't specify that MyTreeView is
the owner of the node.
The exception is raised because RenderChildNodes method uses _owner.Style to
render the stuff,
but in my case the _owner is null.

I hope the guys from Microsoft will resolve this bug in the release version.

And another thing.... I saw that the CreateNode method is declared as
"protected internal virtual"...If this method is internal how am I able to
override it ?!

And to respond to your question, Mark ... I subclassed the TreeView because
I wanted to add drag and drop functionality to the nodes.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 01:44 PM
Derived::Derived(const Base&) developereo@hotmail.com C++ 4 05-23-2007 09:32 AM
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 12:07 AM
Custom Templated Databound Control or derived control? MattC ASP .Net Building Controls 0 11-23-2005 11:49 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57