 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 5th, 2011, 05:18 AM
|
|
Registered User
|
|
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
User Control Email Sending
i have develop a website with email sending capabilty on the basis of one contact form it is sending the email but the information written in the text box is not being fetched out by it
Code:
mailBody = mailBody.Replace("##Name##", Name.Text);
mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
mailBody = mailBody.Replace("##Comments##", Comments.Text);
it is not taking anything in Name.text which is a textbox.
Last edited by papimann; March 5th, 2011 at 05:20 AM..
|
|

March 5th, 2011, 05:37 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
And how does your mail template look?
Imar
|
|

March 5th, 2011, 05:40 AM
|
|
Registered User
|
|
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
did not get you here is the full code
Code:
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", Name.Text);
mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
mailBody = mailBody.Replace("##Comments##", Comments.Text);
MailMessage mymessage = new MailMessage();
mymessage.Subject = "Response from web site";
mymessage.Body = mailBody;
mymessage.From = new MailAddress("[email protected]", "Sender Name");
mymessage.To.Add(new MailAddress("[email protected]", "Receivers Name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(mymessage);
mySmtpClient.EnableSsl = true;
Message.Visible = true;
FormTable.Visible = false;
Hi there,
A user has left the following feedback at the site:
Name: ##Name##
Email Address: ##Email##
Home Phone: ##HomePhone##
Business Phone: ##BusinessPhone##
Comments: ##Comments##
this is the template
|
|

March 5th, 2011, 05:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Looks fine to me, so this should work. Maybe Name gets reset somewhere? Also, make sure that ##Name## etc is exactly the same in the template and in your code, including captilization and spaces.
If this doesn't help, you need to post more code and explain your situation in more detail.
Cheers,
Imar
Last edited by Imar; March 5th, 2011 at 05:56 AM..
|
|

March 5th, 2011, 05:50 AM
|
|
Registered User
|
|
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i am unable to fetch anything from the webpage i.e the contact form
as
Code:
string s = Name.Text.ToString();
this also yields nothing s contains empty string and in the same manner the email which is being send out is like this
Code:
Hi there,
A user has left the following feedback at the site:
Name:
Email Address:
Home Phone:
Business Phone:
Comments:
and not as shown in the book
|
|

March 5th, 2011, 05:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
If this doesn't help, you need to post more code and explain your situation in more detail.
|
Cheers,
Imar
|
|

March 5th, 2011, 06:03 AM
|
|
Registered User
|
|
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
<table class="style1" runat="server" id="FormTable">
<tr>
<td align="center" colspan="3">
<strong>Hello all You Can Contact Us From Here.......</strong></td>
</tr>
<tr>
<td align="center" class="style2">
Name</td>
<td align="left">
<asp:TextBox ID="Name" runat="server"></asp:TextBox>
</td>
<td align="left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Name" CssClass="ErrorMessage"
ErrorMessage="Enter Your Name" Display="Dynamic">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" class="style2">
Email Address</td>
<td align="left">
<asp:TextBox ID="EmailAddress" runat="server"></asp:TextBox>
</td>
<td align="left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="EmailAddress" ErrorMessage="Enter an Email Address"
CssClass="ErrorMessage" Display="Dynamic"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="EmailAddress" ErrorMessage="Enter a Valid Email Address"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
CssClass="ErrorMessage" Display="Dynamic"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="center" class="style2">
Confirm Email Address</td>
<td align="left">
<asp:TextBox ID="ConfirmEmailAddress" runat="server"></asp:TextBox>
</td>
<td align="left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="ConfirmEmailAddress" ErrorMessage="Confirm Email Address"
CssClass="ErrorMessage" Display="Dynamic"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="EmailAddress" ControlToValidate="ConfirmEmailAddress"
ErrorMessage="Retype the Email Address" CssClass="ErrorMessage"
Display="Dynamic"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" class="style2">
Home Phone Number</td>
<td align="left">
<asp:TextBox ID="PhoneHome" runat="server"></asp:TextBox>
</td>
<td align="left">
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="ValidatePhoneNumbers" CssClass="ErrorMessage"
Display="Dynamic" ErrorMessage="Enter Your Home or Business Phone Number"
onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
</td>
</tr>
<tr>
<td align="center" class="style2">
Business Phone Number</td>
<td align="left">
<asp:TextBox ID="PhoneBusiness" runat="server"></asp:TextBox>
</td>
<td align="left">
</td>
</tr>
<tr>
<td align="center" class="style2">
Comments</td>
<td align="left">
<asp:TextBox ID="Comments" runat="server" TextMode="MultiLine"></asp:TextBox>
</td>
<td align="left">
<asp:RequiredFieldValidator CssClass="ErrorMessage"
ID="RequiredFieldValidator4" runat="server"
ControlToValidate="Comments" ErrorMessage="Enter a Comment"
Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" class="style2">
</td>
<td align="center">
<asp:Button ID="SendButton" runat="server" Text="Send"
onclick="SendButton_Click" style="height: 26px" />
</td>
<td align="left">
</td>
</tr>
<tr>
<td align="center" class="style2" colspan="3">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
CssClass="ErrorMessage" ShowMessageBox="True" ShowSummary="False"
HeaderText="Please Correct the following before going foreward" />
</td>
</tr>
</table>
this is the table used and i am not getting user response from this form
|
|

March 5th, 2011, 06:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am sorry, but I am not a mind reader, If you want help, you really need to provide better information. For example:
Where is this code used? In a page or in a User Control? Can you provide the code for both?
What happens when you debug the code? Do you see the controls and do they have a value?
When / how / where exactly do you execute the code that sends the e-mail?
And so on and so forth...
Cheers,
Imar
Last edited by Imar; March 6th, 2011 at 07:08 AM..
|
|
 |