Question ASP.NET CheckBox Value

djreyrey

Member
Joined
Oct 14, 2009
Messages
6
Programming Experience
Beginner
Hello all! Thank you for stopping by.

I'm using the following code to email the values entered in the form. The form was created using the Wizard in the toolbox menu under Standard. The form contains mostly text boxes with a few check boxes. How can I email the check box values? If I use for example, chkBox1.text, that emails the actual check box label and not the "Yes/No" or "True/False" values. If I use chkBox1.checked, I get an error message when I preview the page.


Private Sub SendMail(ByVal from As String, ByVal body As String)
Dim bodyText As String
bodyText = "First Name: " + txtFirst.Text + vbNewLine _
+ "Last Name: " + txtLast.Text + vbNewLine _
+ "Phone Number: " + txtPhone.Text + vbNewLine + vbNewLine _
+ "Selection: "

Dim mailServerName As String = "smtp.mail.net"
Dim message As MailMessage = New MailMessage(from, "email@address.com", "Website Contact", bodyText)
Dim mailClient As SmtpClient = New SmtpClient

mailClient.Host = mailServerName
mailClient.Send(message)
message.Dispose()
End Sub

I really appreciate your time and assistance in this matter.

Rey
 
Try like this:
VB.NET:
Expand Collapse Copy
Dim nline As String = Environment.NewLine
Dim bodyText As String = _
"First Name: " & Me.txtFirst.Text & nline & _
"Last Name: " & Me.txtLast.Text & nline & _
"Selection: " & Me.CheckBox1.Checked.ToString & nline

' test the output
Response.Write(bodyText)
 
Thanks!

Kulrom,

Thank you very much! That did the trick. I appreciate your assistance.

Here's the final outcome in case anyone is interested:

VB.NET:
Expand Collapse Copy
        bodyText = "First Name: " + txtFirst.Text + vbNewLine _
            + "Last Name: " + txtLast.Text + vbNewLine _
            + "Phone Number: " + txtPhone.Text + vbNewLine + vbNewLine _
            + txtComments.Text + chkReport.Checked.ToString

Adding ".checked.ToString" gives the value of the checkbox when sending through email.

Please take care!

Rey
 
Back
Top