This is a discussion on How to Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0 within the C# Programming forums, part of the Software Development category; Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| All Web controls have a RenderControl(HtmlTextWriter) method that, when invoked, renders the control, emitting its resulting markup to the passed-in HtmlTextWriter instance. This programmatic rendering is performed using the following code: StringBuilder SB = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htmlTW = new HtmlTextWriter(SW); WebControlToRenderID.RenderControl(htmlTW); After the above code is executed, the control's rendered HTML can be accessed from the StringBuilder object's ToString() method (i.e., SB.ToString()). In ASP.NET 1.x, this code works wonderfully unless the Web control being rendered is a control that must reside within a WebForm or contains a child control that must reside in a WebForm. For example, Button Web controls must reside within a WebForm. Consequently, if you attempt to use the above code to render a Button Web control or a DataGrid or GridView that contains a Button (or LinkButton or ImageButton) Web control, an exception will be raised complaining that the control is not in a WebForm. Sending the Rendered Control's Markup in an Email Message Once the control's markup has been rendered and stored in a string, we're ready to email it to a specified recipient. Simply send an HTML-formatted email using ASP.NET 2.0's MailMessage and SmtpClient classes in the System.Net.Mail namespace |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Templates for Input/Output in J2ME? | dchips13 | J2ME | 3 | 09-30-2008 04:53 AM |
| How can I print my output? | S.Vinothkumar | C and C++ Programming | 2 | 10-13-2007 12:46 AM |
| Use of Text output value | Shanthi | Testing Tools | 1 | 08-25-2007 02:37 AM |
| use of Custom Control and User Control? | a.deeban | ASP and ASP.NET Programming | 1 | 08-20-2007 08:25 AM |
| How do we prevent browser from caching output of my JSP pages? | oxygen | Java Server Pages (JSP) | 1 | 07-26-2007 04:45 AM |