IT Community - Software Programming, Web Development and Technical Support

How to Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0

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...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-24-2007, 12:35 AM
Archer Archer is offline
D-Web Programmer
 
Join Date: Jun 2007
Posts: 52
Archer is on a distinguished road
Question How to Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0

Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 12:36 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 11:12 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0