Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,829 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,854 people online right now. Registration is fast and FREE... Join Now!




Email Generates Twice, Not Sure why

 
Reply to this topicStart new topic

Email Generates Twice, Not Sure why

ivanjay205
19 Sep, 2008 - 11:37 AM
Post #1

New D.I.C Head
*

Joined: 3 Sep, 2008
Posts: 8

I wrote a VB sub to run behind a submit button so that when a user hits submit, the asp code generates an email and sends to a user.

Here is the code from the vb file

CODE
Protected Sub SendButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendButton.Click

        Dim emailFrom As String
        Dim emailTo As String = "ivan.weiss@elitefse.com"
        Dim emailSubject As String = "Project Work Request"
        Dim emailBody As String
        Dim emailClient As New Mail.SmtpClient("207.41.178.150", 25)

        Select Case RequesterNameDropDownBox.SelectedValue
            Case "Rick DiFilippi"
                emailFrom = "rdifilippi@studioedesigngroup.com"
            Case "Sheron Makara"
                emailFrom = "sheron.makara@elitefse.com"
            Case "Craig Marshall"
                emailFrom = "craig.marshall@elitefse.com"
            Case "Josh Mass"
                emailFrom = "joshua.mass@elitefse.com"
            Case "Mike Simonds"
                emailFrom = "mike.simonds@elitefse.com"
            Case "Mike Watson"
                emailFrom = "michael.watson@elitefse.com"
            Case "Eric Weiss"
                emailFrom = "eric.weiss@elitefse.com"
            Case "Ivan Weiss"
                emailFrom = "ivan.weiss@elitefse.com"
            Case "Vijaye Yarna"
                emailFrom = "vijaye.yarna@elitefse.com"
            Case Else
                emailFrom = "ivan.weiss@elitefse.com"
        End Select

        emailBody = "<p><h2>Client</h2></p><p>Company:  " & ClientCompanyTextBox.Text & "</p><p>Address1:  " & ClientAddress1TextBox.Text & "</p><p>Address2:  " & ClientAddress2Textbox.Text & "</p><p>Phone:  " & ClientPhoneTextBox.Text & "</p><p>Email:  " & ClientEmailTextBox.Text & "</p><p><h2>Architect</h2></p><p>Company:  " & ArchitectCompanyTextBox.Text & "</p><p>Address1:  " & ArchitectAddress1TextBox.Text & "</p><p>Address2:  " & ArchitectAddress2TextBox.Text & "</p><p>Phone:  " & ArchitectPhoneTextBox.Text & "</p><p>Email:  " & ArchitectEmailTextBox.Text & "</p>"
        Try
            Dim emailMessage As New Mail.MailMessage(emailFrom, emailTo, emailSubject, emailBody)
            'Dim emailMessage As New Mail.MailMessage(emailFrom, emailTo)

            emailMessage.IsBodyHtml = True
            emailMessage.Body = emailBody
            emailMessage.Subject = emailSubject

            emailClient.DeliveryMethod = Mail.SmtpDeliveryMethod.Network
            emailClient.Send(emailMessage)
            MsgBox("Email successfully sent.", MsgBoxStyle.Information, "Email Success")
            Exit Sub
        Catch ex As Exception
            MsgBox("Error in sending email.  See System Administrator.", MsgBoxStyle.Critical, "Email Failure")
            Exit Sub
        End Try
    End Sub


Here is the code in the button calling this:

CODE
<div>
        <asp:Button ID="SendButton" Text="Send"
            ToolTip="Click to send project request form" runat="server"
            onclick="SendButton_Click" TabIndex="13" Width="165px" />
    </div>


Any ideas?
User is offlineProfile CardPM
+Quote Post

rollout369
RE: Email Generates Twice, Not Sure Why
23 Oct, 2008 - 06:10 AM
Post #2

New D.I.C Head
*

Joined: 17 Oct, 2008
Posts: 6

I have the same issue. Did you find a fix for it?
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Email Generates Twice, Not Sure Why
23 Oct, 2008 - 06:20 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
I think I have a solution for you, the send is actually being called twice because in your button's click event you have Handles SendButton.Click and in the buttons markup you have onclick="SendButton_Click" . Try removing either of those and see if your problem goes away smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 03:41PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month