473,769 Members | 3,358 Online
Bytes | Software Development & Data Engineering Community
+ 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 BuildPropertyDe tialsInfo() As String
Dim propertyInfoCon trol As New StringBuilder
Dim ms As New MemoryStream
Dim propertyInfoUse rControl As New UserControl
Dim propertyInfoStr ingWriter As New StringWriter(pr opertyInfoContr ol)
Dim propertyInfoHTM LWriter As New HtmlTextWriter( New StreamWriter(ms ))
Dim html As String = String.Empty

Try
propertyInfoHTM LWriter.BeginRe nder()
propertyInfoUse rControl.LoadCo ntrol(renderCon trol)
propertyInfoUse rControl.Render Control(propert yInfoHTMLWriter )
propertyInfoHTM LWriter.EndRend er()
propertyInfoHTM LWriter.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 2426
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**********@d iscussions.micr osoft.comwrote in message
news:CA******** *************** ***********@mic rosoft.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 BuildPropertyDe tialsInfo() As String
Dim propertyInfoCon trol As New StringBuilder
Dim ms As New MemoryStream
Dim propertyInfoUse rControl As New UserControl
Dim propertyInfoStr ingWriter As New
StringWriter(pr opertyInfoContr ol)
Dim propertyInfoHTM LWriter As New HtmlTextWriter( New
StreamWriter(ms ))
Dim html As String = String.Empty

Try
propertyInfoHTM LWriter.BeginRe nder()
propertyInfoUse rControl.LoadCo ntrol(renderCon trol)
propertyInfoUse rControl.Render Control(propert yInfoHTMLWriter )
propertyInfoHTM LWriter.EndRend er()
propertyInfoHTM LWriter.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
9629
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 void Render(HtmlTextWriter writer) {
1
2174
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 being called by the asp.net enginge ??? To be more specific, the thing I currently am most interested in understanding is from which method in the Page class you can know that that the Render method of all aggregated controls have been called...
2
1555
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 contains two instances of htmlEditor, but only textarea (from htmleditor) renderes (java script should be rendered too!)... Dont have source here, but i was hoping that maybe this is trivial, and you would know how to make it work.
4
4220
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 the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and webpage etc.. To Avoid having 1 ASP.Net application running for each client I am attempting a more...
1
3227
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 render, and its clicked event will be triggered properly. Unfortunately I do not have alot of control over where the button shows up.
3
5170
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" The user control has this button on its page. I am outputing the <form runat="server"> inside the render method and have also tried adding it to the page and to the control without any luck. Any help appreciated.
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 custom control that generates everything that will be in the <head> </head> section. This would allow me to make changes on all pages withing a site in one location.
2
11892
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 RenderControl(oHtmlTextWriter) method. Can’t use EnableEventValidation="false". Any help is appreciated. Thanks
13
3559
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 some javascript code that calls window.open. I pass the resource url of page B to Page A's window.open call. Page B is then loaded and executed but none of the server-side code is rendered. If I view the source of the page, the code (and page...
4
2468
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 suspect some permissions problem. I'm running VS.NET 2008 in Vista. Symptoms and observations: * ASP.NET's native ImageMap and Image controls work just fine and provide a design-time preview of images that are referenced via the ImageUrl property *...
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...
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();...
0
5293
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3554
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.