Treeview and rendercontrol

D

David Wiart

Hi,

I try to get the html code of the treeview by doing this :

TreeView Tview = new TreeView();
TreeNode tnode = new TreeNode("Node1", "1");
Tview.Nodes.Add(tnode);
Tview.ID = "Tree1";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Tview.RenderControl(hw);

But I get the following exception and I found no solution for the
moment, please help !!

-----------------------------------------------------------------------------------------------------------------------------------
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)
 

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

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top