Event Procedure firing twice??

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
 
D

Damien

ShaneFowlkes said:
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. =)
I've had this sort of behaviour in the past when I'm using VBs Handles
clause (as you are using), but also stupidly called AddHandler with the
same event and function. Do you use AddHandler? Or do you have
AutoEventWireup set to true or absent in your aspx page? (Not sure
about this last - having never used it)

Damien
 
S

ShaneFowlkes

I'll be d@mned. I removed "Handles btnDelete.Click" from the sub and it
worked fine.

Is this a .NET2 bug? The "Handles" came from VS/VWD itself. I just dbl
clicked the asp:button to start building the sub. I never added it before
when coding by hand.

What cause this behavior? Why would it fire twice?

PS - THANK YOU.
 
S

ShaneFowlkes

BTW - "Do you use AddHandler? Or do you have AutoEventWireup set to true or
absent in your aspx page? (Not sure
about this last - having never used it)"

No to both.
 
D

Damien

ShaneFowlkes said:
I'll be d@mned. I removed "Handles btnDelete.Click" from the sub and it
worked fine.

Is this a .NET2 bug? The "Handles" came from VS/VWD itself. I just dbl
clicked the asp:button to start building the sub. I never added it before
when coding by hand.

What cause this behavior? Why would it fire twice?

PS - THANK YOU.
Hi Shane,

I have to admit, I'm still not developing in 2.0 yet (Most of our apps
are part of ONE BIG APPLICATION in 1.1, so until we migrate the whole
lot, I'm stuck with it).

I can only imagine that something, somewhere is calling AddHandler for
you.

I could only find one similar bug report at the product feedback
centre:

http://lab.msdn.microsoft.com/produ...edbackid=da49d8d6-2b28-422e-bcd2-8cc11498c1d0

but if that's not what you're doing then I don't know.

Sorry I can't be of more assistance,

Damien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top