473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 1067
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jonathan M. Rose | last post by:
I am looking for a script that I can sit on an HTML server (Linux, Apache, PHP/Perl/Python/Etc.) that will allow me to do the following things: 1) Post news articles that consists of (i) a title...
10
by: Fawke101 | last post by:
Hi there, I have a date field in SQL server - that holds dates as DD/MM/YYYY format (GB). Now, i have an ASP application that Adds/Edits records in this table; and i am having real problems...
3
by: John | last post by:
Hi All, I have a database with a button that when it is click it sends an email to the client. This email button works without any problems in other computers. On Thursday we bought a new...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
3
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a...
4
by: Mike Moore | last post by:
What is the best way to launch outlook from an asp.net web page? Can you do this using MAPI or is there a control that you can purchase? We are unable to use SMTP. We use MS Exhange and MAPI...
5
by: Elmo Watson | last post by:
I'm having weird problems emailing on the Win2003 Staging environment - - the same script runs on multiple other computers, but on this one, the smtp service is running, but when the send is done...
2
by: electrixnow | last post by:
I am about to pull my hair out! I have VS 2005 PRO and I am coding in C++ I have a console program that parses data and creates a text output. I need to use MSWords mailmerge to merge the text...
0
by: Alan | last post by:
Hello World: I'm trying to build an application (using Access 2003) that will allow users who have to perform tasks in a particular order, to notify the next person in line when their task is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.