In a project I have developed there is one Web User Control which we
use on 2 different web forms. In addition to using this control on
these web forms we now need to be able to send an email out with the
contents of this user control. How can I instantiate the user control
from code and gain access to the fully rendered HTML source so I can
place it into an email message. Is this possible? I've thought of a
rather dirty way of doing it -- just performing a web request to a
page that contains this control, but I'd rather not go about it this
way. Any ideas you have would be greatly appreciated. Thanks in
advance for your time and effort!
Alexey Smirnov - 02 Oct 2007 08:00 GMT
> In a project I have developed there is one Web User Control which we
> use on 2 different web forms. In addition to using this control on
[quoted text clipped - 6 lines]
> way. Any ideas you have would be greatly appreciated. Thanks in
> advance for your time and effort!
Dim sb as New StringBuilder()
Dim sw as New StringWriter(sb)
Dim tw as New HtmlTextWriter(sw)
myControl.RenderControl(tw)
Dim html as String = sb.ToString()
Steve C. Orr [MCSD, MVP, CSM, ASP Insider] - 02 Oct 2007 08:31 GMT
Use the RenderControl method of the control.
Here's a complete article detailing how to email the rendered HTML of a web
control:
http://aspnet.4guysfromrolla.com/articles/091102-1.aspx

Signature
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
> In a project I have developed there is one Web User Control which we
> use on 2 different web forms. In addition to using this control on
[quoted text clipped - 6 lines]
> way. Any ideas you have would be greatly appreciated. Thanks in
> advance for your time and effort!