Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
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
 
Old October 19th, 2011, 01:07 AM
Authorized User
 
Join Date: Jun 2010
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reg. Contact form with checkbox ....

Hi,
I am creating a Feedack form Using Text Box, Dropdownlist and Check box list



<table runat="server" id="FormTable" align="center" class="style1">
<tr>
<td>
Name</td>
<td>
:-</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Age</td>
<td>
:-</td>
<td>
<asp:DropDownList ID="AgeDropDownList" runat="server">
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>32</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Subject</td>
<td>
:-</td>
<td>
<asp:TextBox ID="SubjectTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
Profession</td>
<td class="style3">
:-</td>
<td class="style3">
<asp:CheckBoxList ID="ProfessionCheckBoxList" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem>Student</asp:ListItem>
<asp:ListItem>Accountant</asp:ListItem>
<asp:ListItem>Engineer</asp:ListItem>
<asp:ListItem>Operator</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style2">
</td>
<td class="style2">
<asp:Button ID="SendButton" runat="server" Text="Send"
onclick="SendButton_Click" />
</td>
</tr>
</table>


Coding of .aspx.css File

protected void SendButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/Contact.txt");
string mailBody = System.IO.File.ReadAllText(fileName);


mailBody = mailBody.Replace("##Name##", NameTextBox.Text);
mailBody = mailBody.Replace("##Age##", AgeDropDownList.SelectedValue);
mailBody = mailBody.Replace("##Subject##", SubjectTextBox.Text);
mailBody = mailBody.Replace("##Profession##", ProfessionCheckBoxList.Text);


MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;

myMessage.From = new MailAddress("[email protected]", "Abhishek Kumar");
myMessage.To.Add(new MailAddress("[email protected]", "Abhishek Kumar"));

SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);

lblMessage.Visible = true;
FormTable.Visible = false;
}
}
}


My problem is that when the user tick More than one check box only the text of first check box
show in the mail and remaining 2nd and third check box text ignored.
 
Old October 19th, 2011, 12:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Have you tried looping through the Items collection and see if the item is checked? You can then access its Text property (which holds the selected subject) which you can append to the mail message.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reg. Contact Form ? Abhishek Kumar BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 16th, 2011 08:26 AM
I need help with contact form iorgusu Need help with your homework? 1 September 27th, 2009 01:56 AM
Contact form? philthy BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 1 July 23rd, 2009 05:14 PM
contact form Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 February 24th, 2009 01:42 PM
Contact Form myself Classic ASP Basics 1 November 18th, 2006 11:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.