0
我有一個按鈕爲什麼我的活動運行兩次?
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" UseSubmitBehavior="False" />
和我的事件是
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("Document_RecordConnectionString1").ToString())
con.Open()
Dim del As New SqlCommand(" delete from TableA where RefNo = '" & Request.QueryString("RefNo") & "'", con)
del.ExecuteNonQuery()
For i As Integer = 0 To displayCBL.Items.Count - 1
If displayCBL.Items(i).Selected Then
Dim cmd As New SqlCommand("Insert into TableA (RefNo,Text,InsertDate) values('" & Request.QueryString("RefNo") & "','" & displayCBL.Items(i).Value & "',getdate())", con)
cmd.ExecuteNonQuery()
End If
Next
con.Close()
End Sub
我發現我的子過程運行兩次,因此插入數據的兩倍(調試器和SQL Server事件探查證實了這一點)。有什麼我想念的嗎?
奇蹟爲什麼有關聯的按鈕並將OnClick功能的兩種方式? – user3454439