Event executed twice

Dohmaker

Member
Joined
Oct 4, 2007
Messages
13
Programming Experience
1-3
hello all,

I am facing a really weird bug on a click event I created. The code works well, but the event is actually executed twice. I tried setting the AutoEventWireup attribute to False, but the problem remained. What could cause this?

here's my code:

VB.NET:
Protected Sub ButtonAjouter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAjouter.Click

        Dim oSQLConn As SqlConnection = New SqlConnection()
        oSQLConn.ConnectionString = "Server=ECAMLMW091;Database=BestEffort_Dev;user=req_priority;password=Er1c550n;Max Pool Size=400"
        'Ouvrir la connexion
        Dim cmd As SqlCommand
        Dim rowsAffected As Integer
        Dim strSQL = "INSERT INTO tbl_Availability (Location, [Date of entry],[Date of Availability],Description,GSDC_Name,PA_Name,MGW_Name)VALUES(@Location, @DateEntry,@DateAvailability,@Description,@GSDC_Name,@PA_Name,@MGW_Name)"
        'Out = File.AppendText(FILENAME)

        'Connect to MSSQL Database


        'Open Connection to DB if closed
        If oSQLConn.State = ConnectionState.Closed Then
            oSQLConn.Open()
        End If

        cmd = New SqlCommand(strSQL, oSQLConn)
        With cmd.Parameters
            .Add(New SqlParameter("@Location", SqlDbType.Char, 10))
            .Add(New SqlParameter("@DateEntry", SqlDbType.DateTime, 8))
            .Add(New SqlParameter("@DateAvailability", SqlDbType.Int, 4))
            .Add(New SqlParameter("@Description", SqlDbType.Text, 16))
            .Add(New SqlParameter("@GSDC_Name", SqlDbType.Char, 10))
            .Add(New SqlParameter("@PA_Name", SqlDbType.Char, 10))
            .Add(New SqlParameter("@MGW_Name", SqlDbType.Char, 10))

        End With

        With cmd
            .Parameters("@Location").Value = (DropdownLocation.Text)
            .Parameters("@DateEntry").Value = (Now)
            .Parameters("@DateAvailability").Value = (DropdownNextAvailable.Text)
            .Parameters("@Description").Value = (TextBoxDescription.Text)
            .Parameters("@GSDC_Name").Value = (DropdownGSDC.Text)
            .Parameters("@PA_Name").Value = (DropDownPA.Text)
            .Parameters("@MGW_Name").Value = (DropdownMGW.Text)


        End With
        Try

            rowsAffected = cmd.ExecuteNonQuery()

        Catch Err As Exception
            Debug.WriteLine(Err.Message.ToString)
            MsgBox(Err.Message.ToString)
            MsgBox(strSQL)
            oSQLConn.Close()
        Finally
            oSQLConn.Close()    'Close Connection
            'Out.Close()

        End Try

    End Sub
 
well I found out what happened. I had specified the event name in the OnClick property of the control, as well as specified that the event handled the click event. I removed the "handles" portion and it only fires once now...

Just thought I'd share...
 
Back
Top