Problems emailing a control

F

Foehammer

I am using the standard .NET method of sending an email. My users will
be filling out a web form with various pieces of information. I have
created a control with properties that are the same as the items on
the form. When the user clicks submit, my code is as follows:

InformationRequest req = new InformationRequest();
req.FirstName = this.txtFirstName.Text;
req.LastName = this.txtLastName.Text;
req.Title = this.txtTitle.Text;
req.Address1 = this.txtAddress1.Text;
req.Address2 = this.txtAddress2.Text;
req.City = this.txtCity.Text;
req.State = this.cboState.SelectedItem.Value;
req.Zip = this.txtZIP.Text;
req.Phone = this.txtPhone.Text;
req.Fax = this.txtFax.Text;

System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter writer = new HtmlTextWriter(sw);
req.RenderControl(writer);

SmtpMail.SmtpServer = "192.168.0.10";
SmtpMail.Send(From, To, Subject, sb.ToString());

//End of code

When I send the email, it comes through, but there is no message body.
In addition, if I try to Response.Write the contents of the
stringbuilder, there isn't anything there. What is causing the control
not to render? All the control contains is a bit of HTML code and <%
%> blocks where it reads from its properties.

Any ideas?

Thanks,
Will Gant
(e-mail address removed)
 
W

William F. Robertson, Jr.

This might not have anything to do with it, but chances are your
InformationRequest WebControl is rendering Html. You should set the
MailMessage.BodyFormat to have it as Html.

If you were to do a Response.Write on sb.ToString() would it render the
proper information to the browser?

//begin code snippet
using System.Web.Mail;

MailMessage email = new MailMessage();

email.From = From;
email.To = To;
email.Subject = Subject;
email.Body = sb.ToString()
email.BodyFormat = MailFormat.Html;

SmtpMail.SmtpServer = "192.168.0.10";
SmtpMail.Send( email );

//end code snippet

HTH,
bill
 
G

Guest

It still comes out completely blank. It seems that calling the RenderControl method doesn't output anything. BTW, the control is a usercontrol, not a server control, if that helps. I set the body format to HTML and it didn't change anything. I think the principal problem is that the control is not dumping out the HTML.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top