473,769 Members | 3,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Render webcontrol to string

I need to get the HTML output from a webcontrol as a string instead of
it being rendered on the page.

I have the following code:
Dim SiteMapSource As New SiteMapDataSour ce()
Dim TreeView1 As New TreeView()
TreeView1.DataS ource = SiteMapSource
TreeView1.ShowE xpandCollapse = True
TreeView1.Expan dDepth = 1
TreeView1.DataB ind()
Dim sb As System.Text.Str ingBuilder = New System.Text.Str ingBuilder()
Using tw As System.IO.Strin gWriter = New System.IO.Strin gWriter(sb)
Using hw As System.Web.UI.H tmlTextWriter = New
System.Web.UI.H tmlTextWriter(t w)
TreeView1.Rende rControl(hw)
Response.Write( sb.ToString())
End Using
End Using

The line with TreeView1.Rende rControl(hw) throws a
NullReferenceEx ception with a almost unusable stacktrace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
System.Web.UI.C ontrol.get_Spac erImageUrl() +59
System.Web.UI.W ebControls.Tree View.RenderBegi nTag(HtmlTextWr iter
writer) +146
System.Web.UI.W ebControls.WebC ontrol.Render(H tmlTextWriter writer)
+17
System.Web.UI.C ontrol.RenderCo ntrolInternal(H tmlTextWriter writer,
ControlAdapter adapter) +25
System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer,
ControlAdapter adapter) +121
System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer) +22
SiteMapTest.Pag e_Load(Object sender, EventArgs e) in
D:\TreeView.asp x.vb:25
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +99
System.Web.UI.C ontrol.LoadRecu rsive() +47
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
+1061

The weird part is that it works fine if I do
Page.Form.Contr ols.add(TreeVie w1) AND it works fine if I use a button
or even a Calendar control...

So, why does TreeView throw a NullReference when asked to render itself
?

Apr 20 '06 #1
0 1749

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2011
by: jb_in_marietta | last post by:
All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control renders fine in run time, but for some reason, it does not render properly in design time. In design time it renders something like this:
0
1598
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone can help me ... My environment: VS 2003 v7.1.3088, Win2K v5.0.2195 SP3, IE6 v6.0.2800.1106 browser. I have a class (C3Menu) derived from WebControl, with a property (MenuItems) that is a collection of menu items. The collection property is...
9
2667
by: kw | last post by:
What is the proper way to get the element ID for a client script? For example, suppose in the WebControl: TextBox t=new TextBox; t.ID=this.ClientID+"X"; .... Then elsewhere we want to access it on the client: Control.Attributes = "javascript:document.getElementById('"+this.ClientID+"X"+"').value= 'test';";
1
3221
by: Earl Teigrob | last post by:
After I have instanced a webcontrol (in code) and set its properties, I would like to get the html that it would render to the display. Can this be done. How??? Earl
3
1454
by: spmm# | last post by:
Hi! Could someone please help me with the following; I have a WebControl that basically looks like this: public class LeftMenu : System.Web.UI.WebControls.WebControl { private string m_CurrentNodeId = string.Empty; public string CurrentNodeId
1
5952
by: Alex Nitulescu | last post by:
Hi. What's the difference between the Render method (overridden when creating custom controls) and the RenderContents method.... (overridden when creating custom controls) ? From MSDN: Render - Sends server control content to a provided HtmlTextWriter object, which writes the content to be rendered on the client.
0
1071
by: tommyw | last post by:
Hi everybody, I'm new to codecomments, but I really hope someone can help me. I am dynamically loading custom controls and user controls into my htmlform control. As I have a lot of "custom" data and controls to use, I am basically creating a string with the markup, using Page.ParseControl to obtain this as a control (with childcontrols) and then adding the result to the form's control collection.
1
1204
by: WT | last post by:
Hello, I recently discovered that Page.Render is doing special things concerning the Menu navigation control. When I was using my own Render override, menus were not working, maybe some style missing, or some javascript not loaded. Any information welcome as I need to do some special work in Render. CS
6
2225
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server" RepeatColumns="3"> <ItemTemplate> <uc:mycontrol id="test" runat="server" /> </ItemTemplate> </asp:DataList> In the code-behind I have something like List<mycontrol lst = new List<mycontrol >;
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7398
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3554
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.