server sends two mails instead of one

B

Barbara Schmidt

Hello,
I made feedback form and it works. There is only a error that the server
sends me two mails instead of one. Here the code:
Imports System.web.Mail
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

Dim objMail As New MailMessage()

objMail.From = txtFrom.Text
objMail.To = my_mail_address@my_domaine.de
objMail.Subject = txtSubject.Text
objMail.Body = txtBody.Text
objMail.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "myserver.de"
SmtpMail.Send(objMail)

End Sub
What to do to make server sends only one mail?
Barbara Schmidt
 
J

Juan T. Llibre

Hi, Barbara,

Do you have AutoEventWireup="true" in your Page directive ?

If you have AutoEventWireup set to true, this method in an aspx or code-behind file
would handle the Click Event of the Button Control with ID "Button1" :

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

( notice : no "handles" )

If you set AutoEventWireup="false", you would need to add the Handles:

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles btnSubmit.Click

Unfortunately, if you have *both* AutoEventWireup="true"
*and* the Handles statement...the method gets executed twice.

That's why you're getting two mails sent.

So, if you need all events wired up explicitly, keep AutoEventWireup="true"
in your Page directive, but take out the Handles statement.

If you don't need all events wired up explicitly, use AutoEventWireup="false"
in your Page directive, and keep the Handles statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top