Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button click event fires twice 1

Status
Not open for further replies.

DeltaTech

Programmer
Apr 16, 2003
92
MY
Hi

When I step through my code, I find that it steps through the Button click event twice.

It's a login form and once the user enters the user name and password, clicking on the submit button causes the code to execute twice.

Can't seem to figure out why.

Anyone can help.

Thanks in advance.
 
2 thoughts:
1. are you using the cassinni(sp) engine provided by VS to debug? sometimes this causes pages to execute multiple times, but this wouldn't be the case on a production server.
2. is the event wired up twice? if so it will execute twice.

if you are using F5 debugging with cassinni configure the web app to use IIS instead for debugging. this may solve the problem.
Another option (assuming you have at least 1 intermediate box between development and production, and that you have some form of logging in place) is to deploy to a testing/staging box and configure logging. walk through the process in questions and review the logs to see what's happening.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Duh!

Finally figured out why the button click event fires twice.

It's a mistake that a beginner like me with no formal training will make.

So, for the benefit of others who might encounter this problem, here is the solution:

If we specify the OnClick event when creating the control, we do not need to add the Handles statement when creating the procedure.

Code:
<form runat="server">
<asp:Button ID="cmdCancel" runat="server" Text="Cancel" [COLOR=red]OnClick="cmdCancel_Click"[/color] />
</form>

Protected Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) [COLOR=red]Handles cmdCancel.Click[/color]
    'Code
End sub

Do one or the other.

Can someone elaborate or correct me if I am wrong please?

Thanks
 
that's it. both handlers were wired to the event so both events fired.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top