473,480 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Render Control Help?

I posted this a week ago, but did not get a respone yet.

I need to render a user control as a HTML string. I do not want the control
to appear on the page, however. Here is what I am doing…
I have an HTML template that will ultimately be sent via e-mail. Inside the
template I have IDs setup for each section that will be replaced with dynamic
data. In one section I need to display a specific kind of data. I already
have a user control that generates what I need. I need to get that control to
fire and then get rendered as HTML to be placed in the appropriate section of
the fore mentioned HTML template. This is the code I have so far:

Public Function BuildPropertyDetialsInfo() As String
Dim propertyInfoControl As New StringBuilder
Dim ms As New MemoryStream
Dim propertyInfoUserControl As New UserControl
Dim propertyInfoStringWriter As New StringWriter(propertyInfoControl)
Dim propertyInfoHTMLWriter As New HtmlTextWriter(New StreamWriter(ms))
Dim html As String = String.Empty

Try
propertyInfoHTMLWriter.BeginRender()
propertyInfoUserControl.LoadControl(renderControl)
propertyInfoUserControl.RenderControl(propertyInfo HTMLWriter)
propertyInfoHTMLWriter.EndRender()
propertyInfoHTMLWriter.Flush()

ms.Position = 0
Dim sr As New StreamReader(ms)
html = sr.ReadToEnd

Catch ex As Exception

End Try
Return html

I donl’t get anything back. I am assuming that I need to add the control to
the collection, but I don’t know how I would do this since I am not working
on a web form. I am inside a class that doens’t have access to a form page.
Any thoughts?

Daniel

Aug 6 '07 #1
1 2409
A UserControl is a Templated Control. If you want a class that doesn't
render a UI, but writes HTML, write a class that uses an HtmlTextWriter to
write to a stream or to a string. An HtmlTextWriter is initialized with a
TextWriter-derived class, which includes both StreamWriter and StringWriter,
so you can use an HtmlTextWriter to build an HTML string as well as writing
to a stream.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Daniel Di Vita" <Da**********@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.com...
>I posted this a week ago, but did not get a respone yet.

I need to render a user control as a HTML string. I do not want the
control
to appear on the page, however. Here is what I am doing.
I have an HTML template that will ultimately be sent via e-mail. Inside
the
template I have IDs setup for each section that will be replaced with
dynamic
data. In one section I need to display a specific kind of data. I already
have a user control that generates what I need. I need to get that control
to
fire and then get rendered as HTML to be placed in the appropriate section
of
the fore mentioned HTML template. This is the code I have so far:

Public Function BuildPropertyDetialsInfo() As String
Dim propertyInfoControl As New StringBuilder
Dim ms As New MemoryStream
Dim propertyInfoUserControl As New UserControl
Dim propertyInfoStringWriter As New
StringWriter(propertyInfoControl)
Dim propertyInfoHTMLWriter As New HtmlTextWriter(New
StreamWriter(ms))
Dim html As String = String.Empty

Try
propertyInfoHTMLWriter.BeginRender()
propertyInfoUserControl.LoadControl(renderControl)
propertyInfoUserControl.RenderControl(propertyInfo HTMLWriter)
propertyInfoHTMLWriter.EndRender()
propertyInfoHTMLWriter.Flush()

ms.Position = 0
Dim sr As New StreamReader(ms)
html = sr.ReadToEnd

Catch ex As Exception

End Try
Return html

I donl't get anything back. I am assuming that I need to add the control
to
the collection, but I don't know how I would do this since I am not
working
on a web form. I am inside a class that doens't have access to a form
page.
Any thoughts?

Daniel

Aug 7 '07 #2

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

Similar topics

2
9571
by: George Ter-Saakov | last post by:
I am trying to wrap PlaceHolder so it will output prefix/suffix (like <div>, </div>) before render the actual control. So i created public class clsSection : PlaceHolder protected override...
1
2155
by: Tomas | last post by:
Is there any sequence diagram on the web that clearly shows in which order all Page methods (load, render and so on) are being called compared to the order the page's contained control methods are...
2
1537
by: Jeti [work] | last post by:
I'm using ASP.NET (Framework 1.1), and have encountered folowing problem: I have testing page: "testing.aspx", and i have created two controls (register and htmlEditor). register control...
4
4199
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
1
3210
by: sonic | last post by:
I generate a button link control in following Manner. Button b = new Button(); b.Click = MyEventHandler(...); If i add this button to current control with: this.Controls.Add( b ); it will...
3
5142
by: John Hughes | last post by:
I'm trying to add a user control to a form via the pages render method and I get the following error : "Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server" ...
2
529
by: Frank | last post by:
From: "Frank" <fkaesser@pfmail.com> Subject: Can I Use HTML Text Writer i a Custom Control to Render the <head> Section? Date: Wednesday, January 18, 2006 11:38 AM I would like to create a...
2
11870
by: Albert | last post by:
I’ve been getting this error after converting my app from .NET 1.1 to .Net 2.0. RegisterForEventValidation can only be called during Render() An error occurs when I call ...
13
3511
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
4
2443
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
6915
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...
1
6750
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...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4794
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...
0
4493
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...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
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...

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.