S
ShaneFowlkes
I have a odd thing happening. I have a sub that is called upon a button
click and it seems to be firing TWICE. I have no idea how this is happening
but I suspect is has something to do with page_load and IsPostBack.
The page has a form that displays a record. The user can delete the record
by clicking a delete button or update it by clicking an update button. The
delete sub calls a couple of other subs and functions and then displays a
confirmation message or an error. In my case...it's doing BOTH. I had
another classic VB developer look over it with me and we're both stumped.
I would love to post a URL but this still in early development and not live.
We even put temp counters in place and wrote them to the page and the delete
sub is indeed running twice. It deletes the record just fine and then runs
again and displays the error message since the MS SQL didn't delete the
record successfully (a second time).
Surely, I must be missing something obvious. Help is much appreciated!! The
person who figures this out gets a lifetime membership card to Hooters. =)
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
If Page.IsPostBack = False Then
'Load form with data
End If
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim strDeleteResponse As String
strDeleteResponse = DeleteItem(intItemID)
If strDeleteResponse = "OK" Then
'display confirmation message & clear fields
Else
'display error message from function
End If
End Sub
Protected Function DeleteItem(ByVal intItemID As Integer) As String
'function calls a MS SQL stored procedure and returns "OK" or the
actual MS SQL error message
End Function
click and it seems to be firing TWICE. I have no idea how this is happening
but I suspect is has something to do with page_load and IsPostBack.
The page has a form that displays a record. The user can delete the record
by clicking a delete button or update it by clicking an update button. The
delete sub calls a couple of other subs and functions and then displays a
confirmation message or an error. In my case...it's doing BOTH. I had
another classic VB developer look over it with me and we're both stumped.
I would love to post a URL but this still in early development and not live.
We even put temp counters in place and wrote them to the page and the delete
sub is indeed running twice. It deletes the record just fine and then runs
again and displays the error message since the MS SQL didn't delete the
record successfully (a second time).
Surely, I must be missing something obvious. Help is much appreciated!! The
person who figures this out gets a lifetime membership card to Hooters. =)
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
If Page.IsPostBack = False Then
'Load form with data
End If
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim strDeleteResponse As String
strDeleteResponse = DeleteItem(intItemID)
If strDeleteResponse = "OK" Then
'display confirmation message & clear fields
Else
'display error message from function
End If
End Sub
Protected Function DeleteItem(ByVal intItemID As Integer) As String
'function calls a MS SQL stored procedure and returns "OK" or the
actual MS SQL error message
End Function