tags:

views:

205

answers:

1

I'm using the openFileDialog in sliverlight 2.0 with vb.net in the back end. I have it wired up and it is working as it is suppose to except that the click event seems to fire twice. It fires the first time, i select the files and click ok. it does the processing. But as soon as i click ok, the click event fires a second time and the dialog box comes up again. that is not what i want and i'm not sure what i'm doing wrong that it comes up that second time. Here is the code.. hopefully someone see's what i'm doing wrong.

<Button x:Name="bOpenFileDialog" Content="2. Import CSV"
             Height="30" Width="200" Margin="0,96,0,0"
             HorizontalAlignment="Left" VerticalAlignment="Top" 
             Click="bOpenFileDialog_Click" />
    <TextBlock Height="19" Margin="246,26,261,0" VerticalAlignment="Top" Text="TextBlock" TextWrapping="Wrap" x:Name="lblMsg"/>

 Private Sub bOpenFileDialog_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles bOpenFileDialog.Click
    Me.bOpenFileDialog.IsEnabled = False
    ' Create an instance of the open file dialog box.
    Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog


    ' Set filter options and filter index.
    openFileDialog1.Filter = "LOG Files (*.log)|*.log|All Files (*.*)|*.*"
    openFileDialog1.FilterIndex = 1

    openFileDialog1.Multiselect = True

    ' Call the ShowDialog method to show the dialogbox.
    Dim UserClickedOK As Boolean = CBool(openFileDialog1.ShowDialog)

    ' Process input if the user clicked OK.
    If (UserClickedOK = True) Then
        Dim rows As Integer = openFileDialog1.Files.Count - 1
        ReDim aryIISLogs(rows)

        For i As Integer = 0 To openFileDialog1.Files.Count - 1
            aryIISLogs(i) = openFileDialog1.Files(i).Name
        Next
        Process1File()
    End If
End Sub

Thanks Shannon

A: 

I think this is because you register the event twice: you have it in the button definition:

Click="bOpenFileDialog_Click"

and in the method definition:

Private Sub bOpenFileDialog_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles bOpenFileDialog.Click

Each of these triggers the event, so you have two popups. If you remove either "Click=" or "handles" you'll get the event to fire only once.

boredgeek