PaisaFever Shakshi
PaisaFever Shakshi

Reputation: 31

Why is this insert code inserting data twice on button clicks?

The following code inserts same data two time in database table, but I want it to insert only one item when button is clicked.

What is the problem in this code?

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

    If RadUpload1.UploadedFiles.Count >= 0 Then
        Dim file As UploadedFile = RadUpload1.UploadedFiles(0)
        SqlDataSource1.InsertParameters("photo").DefaultValue = "./upload/" & file.GetName()
        'SqlDataSource1.InsertParameters("name").DefaultValue = TextBox1.Text
        SqlDataSource1.Insert()
        ListView1.DataBind()
    End If
    'UpdateProgressContext()
End Sub

Upvotes: 0

Views: 1765

Answers (1)

Pawan Nogariya
Pawan Nogariya

Reputation: 8990

You must be using both OnClick="Button1_Click" in your markup and Handles Button1.Click in your procedure. Try removing one of them.

Upvotes: 2

Related Questions