 |
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics 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
|
|
|

September 11th, 2010, 08:46 PM
|
Registered User
|
|
Join Date: Feb 2009
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
email to send user data from contact form CheckBoxList
Hi,
I have been successful in sending all user data from contact forms to email except for the CheckBoxList. It only sends one value no matter how many boxes I have checked.
The following is the code for the checkbox in the .ascx code:
Code:
<asp:CheckBoxList ID="dayCheckBoxList" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Value="monday">monday</asp:ListItem>
<asp:ListItem Value="tuesday">tuesday</asp:ListItem>
<asp:ListItem Value="wednesday">wednesday</asp:ListItem>
<asp:ListItem Value="thursday">thursday</asp:ListItem>
<asp:ListItem Value="friday">friday</asp:ListItem>
<asp:ListItem Value="saturday">saturday</asp:ListItem>
<asp:ListItem Value="sunday">sunday</asp:ListItem>
</asp:CheckBoxList><br />
The code behind .ascx.cs
Code:
mailbody = mailbody.Replace("##Name##", txtName.Text);
mailbody = mailbody.Replace("##Email##", txtEmailAddress.Text);
mailbody = mailbody.Replace("##HomePhone##", txtPhoneHome.Text);
mailbody = mailbody.Replace("##BusinessPhone##", txtPhoneBusiness.Text);
mailbody = mailbody.Replace("##Comments##", txtComments.Text);
mailbody = mailbody.Replace("##Smallpox##", Smallpox.Checked ? "Yes" : "No");
mailbody = mailbody.Replace("##Mumps##", Mumps.Checked ? "Yes" : "No");
mailbody = mailbody.Replace("##Item##", itemDropDownList.SelectedValue);
mailbody = mailbody.Replace("##Color##", colorListBox.SelectedValue);
mailbody = mailbody.Replace("##Day##", dayCheckBoxList.SelectedValue);
mailbody = mailbody.Replace("##StarTrek##", startrekRadioButtonList.SelectedValue);
foreach (ListItem item in dayCheckBoxList.Items)
{
if (item.Selected == true)
{
dayCheckBoxList.SelectedValue += item.Value;
}
}
The ContactForm.txt with placeholders:
Code:
Hello MyValuedClient,<br /><br />
A user has entered the following feedback at MyTampaWebDesign:<br /><br />
<table>
<tr><td>Name:<br /></td> <td> ##Name##<br /></td></tr>
<tr><td>E-mail address:<br /></td> <td> ##Email##<br /></td></tr>
<tr><td>Home phone:<br /></td> <td> ##HomePhone##<br /></td></tr>
<tr><td>Business phone:<br /></td> <td> ##BusinessPhone##<br /></td></tr>
<tr><td>Comments:<br /></td> <td> ##Comments##<br /></td></tr>
<tr><td>Smallpox:<br /></td> <td> ##Smallpox##<br /></td></tr>
<tr><td>Mumps:<br /></td> <td> ##Mumps##<br /></td></tr>
<tr><td>Item no.:<br /></td> <td> ##Item##<br /></td></tr>
<tr><td>Color:<br /></td> <td> ##Color##<br /></td></tr>
<tr><td>Day:<br /></td> <td> ##Day##<br /></td></tr>
<tr><td>StarTrek:<br /></td> <td> ##StarTrek##<br /></td></tr>
</table>
<br/><br />
Thanks,<br />
MyTampaWebDesign
Has anyone experienced the same issue?
Thanks,
tompatamcat
|

September 12th, 2010, 03:35 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You shouldn't reassign the selected value, but store it in a local variable and use that as a replacement value for the mail template. E.g.:
Code:
string result = string.Empty;
foreach (ListItem item in dayCheckBoxList.Items)
{
if (item.Selected == true)
{
result += item.Value;
}
}
Then you can use result in the Replace method call.
Hope this helps,
Imar
|
The Following 2 Users Say Thank You to Imar For This Useful Post:
|
|

September 12th, 2010, 02:28 PM
|
Registered User
|
|
Join Date: Feb 2009
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks Imar!
Your suggestion worked.
I also discovered that my foreach block needed to precede the Replace method call.
tompatamcat
|

September 12th, 2012, 11:58 PM
|
Registered User
|
|
Join Date: Sep 2012
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I purchased the Beginning ASP.Net 4 in C# and VB by Imar and thought pretty cool he had responded to a request above. Regardless.....I am having the same issue and not sure when you mention that "you can use result in the Replace method call" what would that line of code look like in the mailBody = mailBody.Replace section of the .cs file?
|

September 13th, 2012, 08:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Just replace mailBody with result, as that variable now contains the e-mail's body....
Cheers,
Imar
|

September 13th, 2012, 11:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Sorry, wrong answer. You now use result for the value you want to replace the placeholder with:
mailbody = mailbody.Replace("##YourKey##", result);
Hope this helps,
Imar
|
The Following User Says Thank You to Imar For This Useful Post:
|
jakek (September 13th, 2012)
|

March 26th, 2013, 12:11 AM
|
Registered User
|
|
Join Date: Mar 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Hi there,
You shouldn't reassign the selected value, but store it in a local variable and use that as a replacement value for the mail template. E.g.:
Code:
string result = string.Empty;
foreach (ListItem item in dayCheckBoxList.Items)
{
if (item.Selected == true)
{
result += item.Value;
}
}
Then you can use result in the Replace method call.
Hope this helps,
Imar
|
It help me very much..thank you imar..
|
|
 |