Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 11th, 2010, 08:46 PM
Registered User
 
Join Date: Feb 2009
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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>&nbsp;&nbsp;##Name##<br /></td></tr>
<tr><td>E-mail address:<br /></td>   <td>&nbsp;&nbsp;##Email##<br /></td></tr>
<tr><td>Home phone:<br /></td>       <td>&nbsp;&nbsp;##HomePhone##<br /></td></tr>
<tr><td>Business phone:<br /></td>   <td>&nbsp;&nbsp;##BusinessPhone##<br /></td></tr>
<tr><td>Comments:<br /></td>         <td>&nbsp;&nbsp;##Comments##<br /></td></tr>
<tr><td>Smallpox:<br /></td>         <td>&nbsp;&nbsp;##Smallpox##<br /></td></tr>
<tr><td>Mumps:<br /></td>             <td>&nbsp;&nbsp;##Mumps##<br /></td></tr>
<tr><td>Item no.:<br /></td>         <td>&nbsp;&nbsp;##Item##<br /></td></tr>
<tr><td>Color:<br /></td>             <td>&nbsp;&nbsp;##Color##<br /></td></tr>
<tr><td>Day:<br /></td>                 <td>&nbsp;&nbsp;##Day##<br /></td></tr>
<tr><td>StarTrek:<br /></td>         <td>&nbsp;&nbsp;##StarTrek##<br /></td></tr>
</table>

<br/><br />

Thanks,<br />
MyTampaWebDesign
Has anyone experienced the same issue?

Thanks,
tompatamcat
  #2 (permalink)  
Old September 12th, 2010, 03:35 AM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following 2 Users Say Thank You to Imar For This Useful Post:
et_leen (March 26th, 2013), tompatamcat (September 12th, 2010)
  #3 (permalink)  
Old September 12th, 2010, 02:28 PM
Registered User
 
Join Date: Feb 2009
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Imar!

Your suggestion worked.

I also discovered that my foreach block needed to precede the Replace method call.

tompatamcat
  #4 (permalink)  
Old September 12th, 2012, 11:58 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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?
  #5 (permalink)  
Old September 13th, 2012, 08:53 AM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Just replace mailBody with result, as that variable now contains the e-mail's body....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #6 (permalink)  
Old September 13th, 2012, 11:07 AM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
jakek (September 13th, 2012)
  #7 (permalink)  
Old March 26th, 2013, 12:11 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2013
Location: Malaysia
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to et_leen
Default

Quote:
Originally Posted by Imar View Post
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..
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to deliver the contact form information on yahoo email ? Abhishek Kumar ASP.NET 3.5 Basics 1 June 15th, 2010 10:52 AM
Chapter 9 pps 314-316 Contact Form User Control Featheriver BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 February 2nd, 2009 03:19 AM
email contact forms xeno Beginning PHP 0 July 30th, 2005 07:36 AM
Send form data using VB ratheeshpkr Pro VB 6 8 October 18th, 2004 07:29 AM



All times are GMT -4. The time now is 03:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.