Spacer Image URL error
-
Hi, I tried to initialize a new TreeView control in ASP.NET 2.0, so I could display its HTML output through the RenderControl method. But when I run the website I get the following error:
[NullReferenceException: Object reference not set to an instance of an object.] System.Web.UI.Control.get_SpacerImageUrl() +59 System.Web.UI.WebControls.TreeView.RenderBeginTag(HtmlTextWriter writer) +147 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +17 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +53 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +280 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24 Test.button1_Click(Object sender, EventArgs e) in c:\... System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
Since the stack trace terminates at the methodget_SpacerImageUrl()
, I assume that I didn't set some property of the TreeView control when I was intializing it. Anybody know which property I have to set to avoid this error? Or am I completely off the mark? I initialized the TreeView control as follows:TreeView tv = new TreeView(); tv.ImageSet = TreeViewImageSet.Inbox; tv.ShowLines = true; tv.ID = "treeViewTest"; tv.Nodes.Add(new TreeNode("test")); StringBuilder sw = new StringBuilder(); //stores the HTML of the TreeView Control StringWriter st = new StringWriter(sw); HtmlTextWriter writer = new HtmlTextWriter(st); tv.RenderControl(writer);//outputs the html of the treeview control to writer labelContent.Text = Server.HtmlEncode(sw.ToString());
Thanks. -
Hi, I tried to initialize a new TreeView control in ASP.NET 2.0, so I could display its HTML output through the RenderControl method. But when I run the website I get the following error:
[NullReferenceException: Object reference not set to an instance of an object.] System.Web.UI.Control.get_SpacerImageUrl() +59 System.Web.UI.WebControls.TreeView.RenderBeginTag(HtmlTextWriter writer) +147 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +17 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +53 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +280 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24 Test.button1_Click(Object sender, EventArgs e) in c:\... System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
Since the stack trace terminates at the methodget_SpacerImageUrl()
, I assume that I didn't set some property of the TreeView control when I was intializing it. Anybody know which property I have to set to avoid this error? Or am I completely off the mark? I initialized the TreeView control as follows:TreeView tv = new TreeView(); tv.ImageSet = TreeViewImageSet.Inbox; tv.ShowLines = true; tv.ID = "treeViewTest"; tv.Nodes.Add(new TreeNode("test")); StringBuilder sw = new StringBuilder(); //stores the HTML of the TreeView Control StringWriter st = new StringWriter(sw); HtmlTextWriter writer = new HtmlTextWriter(st); tv.RenderControl(writer);//outputs the html of the treeview control to writer labelContent.Text = Server.HtmlEncode(sw.ToString());
Thanks.You need to add the TreeView control to the control hierarchy of the current Page, also the rendering will cause the error if the form does not get rendered or the Page is not in the callback. I'm curious that why you don't just add the TreeView control to the Page and leave it render normally.