Output asp.net masterpage webform to html email

Posted by Steve McCall on Stack Overflow See other posts from Stack Overflow or by Steve McCall
Published on 2010-03-19T11:38:20Z Indexed on 2010/03/19 11:41 UTC
Read the original article Hit count: 733

Filed under:
|
|

Hi I'm having a bit of a nightmare here!

I'mv trying output a webform to html using page.rendercontrol and htmltextwriter but it is resulting in a blank email.

Code:

   StringBuilder sb = new StringBuilder();
   StringWriter sw = new StringWriter(sb);
   HtmlTextWriter htmlTW = new HtmlTextWriter(sw);

   page.RenderControl(htmlTW);

   String content = sb.ToString();

   MailMessage mail = new MailMessage();

   mail.From = new MailAddress("[email protected]");
   mail.To.Add("[email protected]");
   mail.IsBodyHtml = true;

   mail.Subject = "Test";
   mail.Body = content;

    SmtpClient smtp = new SmtpClient("1111");
    smtp.Send(mail);

    Response.Write("Message Sent");

I also tried it by rendering a single textbox and got and error saying It needed to be within form tags (which are on the masterpage).

I tried this fix: http://forums.asp.net/p/1016960/1368933.aspx#1368933 and added:

public override void 

VerifyRenderingInServerForm(Control control) { return; }

But now the errror I get is:

VerifyRenderingInServerForm(Control)': no suitable method found to override

Does anyone have a fix for this? I'm tearing my hair out!!

Thanks,

Steve

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about rendercontrol