469,133 Members | 1,037 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Event Procedure firing twice??

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


Apr 13 '06 #1
4 4107
ShaneFowlkes wrote:
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

Apr 13 '06 #2
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.
"Damien" <Da*******************@hotmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
ShaneFowlkes wrote:
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

Apr 13 '06 #3
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.

"ShaneFowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:e7**************@TK2MSFTNGP02.phx.gbl... 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.
"Damien" <Da*******************@hotmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
ShaneFowlkes wrote:
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


Apr 13 '06 #4
ShaneFowlkes wrote:
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/produc...2-8cc11498c1d0

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

Sorry I can't be of more assistance,

Damien

Apr 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Seraph | last post: by
1 post views Thread by Diana | last post: by
2 posts views Thread by John Kotuby | last post: by
18 posts views Thread by joaotsetsemoita | last post: by
2 posts views Thread by =?Utf-8?B?SGV6YWw=?= | last post: by
3 posts views Thread by =?Utf-8?B?QmFycnkgR2lsYmVydA==?= | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.