PaisaFever Shakshi PaisaFever Shakshi - 1 year ago 98
ASP.NET (C#) Question

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
End If
End Sub

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download