neondestruction
New member
- Joined
- Nov 1, 2007
- Messages
- 2
- Programming Experience
- Beginner
I'm fairly new to VB.NET, so I'll try to explain this as best as I can.
I have created a form that contains 2 sets of radiobuttonlists asking 2 questions. I store the answers to the 2 radiobuttonlists in variables, and then insert those answers into the body of a mail message.
All of that logic works fine. However, when I click the submit button, the maiil message fails to send on the first click. If I click it again, the mail message is sent, but always with the previous "click's" variables. So basically the mail message information is always one behind, if that makes any sense.
Here is the code:
Can anyone help me out please?
I have created a form that contains 2 sets of radiobuttonlists asking 2 questions. I store the answers to the 2 radiobuttonlists in variables, and then insert those answers into the body of a mail message.
All of that logic works fine. However, when I click the submit button, the maiil message fails to send on the first click. If I click it again, the mail message is sent, but always with the previous "click's" variables. So basically the mail message information is always one behind, if that makes any sense.
Here is the code:
VB.NET:
Sub Button1_Click(sender As Object, e As EventArgs)
' Build a MailMessage
Dim mailMessage = New MailMessage
'Int for counting rows in TLAssociates table
Dim I As Integer = 0
'String for storing e-mail addresses of Techlab Associates
Dim fromString as String
'dataset for looping through the dataset
Dim emailSet As System.Data.DataSet = GetTLEmails()
'Loop created to obtain e-mail addresses
For I = 0 To emailSet.Tables(0).Rows.Count - 1
If I = 0
fromString = emailSet.Tables(0).Rows(I).Item("Email")
Else
fromString = fromString + ", " + emailSet.Tables(0).Rows(I).Item("Email")
End If
Next
mailMessage.From = fromString
mailMessage.To = "xxxxxxxxxxxxxxxxxx"
mailMessage.Subject = "Chicken or Fish?"
mailMessage.BodyFormat = MailFormat.Html
Dim Chicken as String
Dim Fish as String
If chickenRBL.SelectedItem.text = "No"
Chicken = "does not like"
Else
Chicken = "does like"
End If
If FishRBL.SelectedItem.text = "No"
Fish = "does not like"
Else
Fish = "does like"
End If
Dim mailBody as String = "This person " + Chicken + " chicken. <BR>" + "This person " + Fish + " fish. <BR>"
mailMessage.Body = mailBody
System.Web.Mail.SmtpMail.SmtpServer = "xxxxxxxxxxxxxxx"
System.Web.Mail.SmtpMail.Send(mailMessage)
sentChicken.text = Chicken
sentChicken.visible = true
sentFish.text = Fish
sentFish.visible = true
chicken = ""
fish = ""
End Sub
Can anyone help me out please?
Last edited by a moderator: