469,572 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

Problems emailing a control

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
Fo*******@hotmail.com
Nov 18 '05 #1
2 991
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

"Foehammer" <fo*******@hotmail.com> wrote in message
news:27**************************@posting.google.c om...
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
Fo*******@hotmail.com

Nov 18 '05 #2
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.

"William F. Robertson, Jr." wrote:
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

"Foehammer" <fo*******@hotmail.com> wrote in message
news:27**************************@posting.google.c om...
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
Fo*******@hotmail.com


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jonathan M. Rose | last post: by
10 posts views Thread by Fawke101 | last post: by
4 posts views Thread by Mike Moore | last post: by
5 posts views Thread by Elmo Watson | last post: by
2 posts views Thread by electrixnow | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.