Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > TreeView in Web Custom Control

Reply
Thread Tools

TreeView in Web Custom Control

 
 
Jonas
Guest
Posts: n/a
 
      05-18-2006
Hi.
I'm trying to develop a web custom control that uses a programmatically
created treeview.
My problem is that I get an exception when I try to render the control.
With properties do I have to assign to get this working.
Here is some sample code:

namespace WebControlLibrary1
{
[ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]
public class MyControl : WebControl
{
protected override void RenderContents(HtmlTextWriter output)
{
XmlDataSource source = new XmlDataSource();
source.Data = GetXmlElement().OuterXml;

TreeView tv = new TreeView();
tv.ID = ClientID + "_TreeView";
tv.ImageSet = TreeViewImageSet.XPFileExplorer;
tv.RenderControl(output);
}

private XmlElement GetXmlElement()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Xml><EmptyXml /></Xml>");
return doc.DocumentElement;
}
}
}


Best regards
Jonas Samuelsson

 
Reply With Quote
 
 
 
 
Jonas
Guest
Posts: n/a
 
      05-22-2006
Hi,
here is the exception info:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="System.Web"
StackTrace:
at System.Web.UI.Control.get_SpacerImageUrl()
at
System.Web.UI.WebControls.TreeView.RenderBeginTag( HtmlTextWriter
writer)
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter
writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at WebControlLibrary1.MyControl.RenderContents(HtmlTe xtWriter
output) in C:\Work\WebSite1\WebControlLibrary1\MyControl.cs:l ine 27
at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter
writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter
writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at
System.Web.UI.HtmlControls.HtmlForm.RenderChildren (HtmlTextWriter
writer)
at
System.Web.UI.HtmlControls.HtmlContainerControl.Re nder(HtmlTextWriter
writer)
at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTex tWriter
output)
at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at
System.Web.UI.HtmlControls.HtmlForm.RenderControl( HtmlTextWriter
writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter
writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 
Reply With Quote
 
 
 
 
Prakash V
Guest
Posts: n/a
 
      06-07-2006
Hi ,
i too got the same problem, i try to render a treecontrol and pass
the html to some other mehthod, it give object set to null exception, i
tried many things but cannot do it, i tried to replace get_spacerImageurl()
but no use. Did anyone have solution for this problem

part of my code is
private string RenderTree()

{


TreeView Tview = new TreeView();

TreeNode tnode = new TreeNode("Node1", "1");

Tview.Nodes.Add(tnode);

Tview.ID = "Tree1";


StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

HtmlTextWriter htmlTW = new HtmlTextWriter(sw);

Tview.RenderControl(htmlTW);

return sb.ToString();

}

and stack trace is [NullReferenceException: Object reference not set to an
instance of an object.]
System.Web.UI.Control.get_SpacerImageUrl() +50
System.Web.UI.WebControls.TreeView.RenderBeginTag( HtmlTextWriter writer)
+202
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +31
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +74
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter) +291
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
TreeviewRender.RenderTree() in
d:\TestProject\TestProject\TreeviewRender.aspx.cs: 30
TreeviewRender.Page_Load(Object sender, EventArgs e) in
d:\TestProject\TestProject\TreeviewRender.aspx.cs: 17
System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o,
Object t, EventArgs e) +31
System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender,
EventArgs e) +68
System.Web.UI.Control.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3030







"Gaurav Vaish (EduJini.IN)" <(E-Mail Removed)> wrote in
message news:%(E-Mail Removed)...
> Cryptic only with the exception that SpacerImageUrl is missing.
> Provided any value to it?
> Or may be something coming out of MyControl.cs
>
> Mail me the relevant code (with aspx) at
> gaurav~DOT~vaish[at]gmail~DOT~com... not sure, but probably may be of some
> help.
>
> --
> Happy Hacking,
> Gaurav Vaish
> http://www.mastergaurav.org
> http://www.edujini.in
> -------------------
>
>
> "Jonas" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
>> Hi,
>> here is the exception info:
>>
>> System.NullReferenceException was unhandled by user code
>> Message="Object reference not set to an instance of an object."
>> Source="System.Web"
>> StackTrace:
>> at System.Web.UI.Control.get_SpacerImageUrl()
>> at
>> System.Web.UI.WebControls.TreeView.RenderBeginTag( HtmlTextWriter
>> writer)
>> at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter
>> writer)
>> at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
>> writer, ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
>> ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
>> at WebControlLibrary1.MyControl.RenderContents(HtmlTe xtWriter
>> output) in C:\Work\WebSite1\WebControlLibrary1\MyControl.cs:l ine 27
>> at System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter
>> writer)
>> at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
>> writer, ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
>> ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
>> at System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter
>> writer, ICollection children)
>> at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
>> at
>> System.Web.UI.HtmlControls.HtmlForm.RenderChildren (HtmlTextWriter
>> writer)
>> at
>> System.Web.UI.HtmlControls.HtmlContainerControl.Re nder(HtmlTextWriter
>> writer)
>> at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTex tWriter
>> output)
>> at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
>> writer, ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
>> ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
>> at
>> System.Web.UI.HtmlControls.HtmlForm.RenderControl( HtmlTextWriter
>> writer)
>> at System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter
>> writer, ICollection children)
>> at System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
>> at System.Web.UI.Control.Render(HtmlTextWriter writer)
>> at System.Web.UI.Page.Render(HtmlTextWriter writer)
>> at System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter
>> writer, ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
>> ControlAdapter adapter)
>> at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
>> at System.Web.UI.Page.ProcessRequestMain(Boolean
>> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>>

>
>



 
Reply With Quote
 
Jonas
Guest
Posts: n/a
 
      06-12-2006
I got it working by adding the following line:
treeview.SkipLinkText = "";
before treeview.RenderControl(writer).

Thanks alot Gaurav!

 
Reply With Quote
 
Prakash V
Guest
Posts: n/a
 
      06-12-2006
Hi,
after adding treeview.SkipLinkText = ""; also it's not working, it now
expects GetImageUrl. i am giving my code and stack trace below.

public partial class TreeviewRender : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (IsPostBack)

RenderTree();

}

private string RenderTree()

{

TreeView Tview = new TreeView();

TreeNode tnode = new TreeNode("Node1", "1");

Tview.Nodes.Add(tnode);

Tview.ID = "Tree1";

Tview.SkipLinkText = "";

StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

HtmlTextWriter htmlTW = new HtmlTextWriter(sw);

Tview.RenderControl(htmlTW);

return sb.ToString();

}

}


Source Error:


Line 30: StringWriter sw = new StringWriter(sb);
Line 31: HtmlTextWriter htmlTW = new HtmlTextWriter(sw);
Line 32: Tview.RenderControl(htmlTW);
Line 33: return sb.ToString();
Line 34:


Source File: d:\TestProject\TestProject\TreeviewRender.aspx.cs Line: 32

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
System.Web.UI.WebControls.TreeView.GetImageUrl(Int 32 index) +4107
System.Web.UI.WebControls.TreeNode.Render(HtmlText Writer writer, Int32
position, Boolean[] isLast, Boolean enabled) +2700
System.Web.UI.WebControls.TreeView.RenderContents( HtmlTextWriter writer)
+294
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +43
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer,
ControlAdapter adapter) +74
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter) +291
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
TreeviewRender.RenderTree() in
d:\TestProject\TestProject\TreeviewRender.aspx.cs: 32
TreeviewRender.Page_Load(Object sender, EventArgs e) in
d:\TestProject\TestProject\TreeviewRender.aspx.cs: 18
System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o,
Object t, EventArgs e) +31
System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender,
EventArgs e) +68
System.Web.UI.Control.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3034



Thanks in Advance,
Prakash.V
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.42

"Jonas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I got it working by adding the following line:
> treeview.SkipLinkText = "";
> before treeview.RenderControl(writer).
>
> Thanks alot Gaurav!
>



 
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
TreeView in Web Custom Control Jonas ASP .Net 9 10-11-2007 07:45 AM
Disappearing asp:TreeView in a custom web control 6doughnuts@googlemail.com ASP .Net Web Controls 0 11-03-2006 05:04 PM
TreeView in Web Custom Control Jonas ASP .Net Web Controls 4 06-12-2006 09:50 AM
Issue with a custom TreeView derived from the TreeView control Ionutz ASP .Net Web Controls 2 10-23-2005 03:23 PM
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