Last post Mar 31, 2016 07:57 AM by Candice Zhou
Mar 30, 2016 08:13 AM|mojo99|LINK
I have a button on a form which writes data to a database. Code works fine. When I'm in design view in Visual Studio however, and double-click on the button to go to the underlying code, something I've not seen before happens.
Normally the code would look like this:
Protected Sub btnSaveToDB_Click(sender As Object, e As EventArgs) Handles btnSaveToDb.Click
Double-clicking on the button in design view, however, produces this:
Protected Sub btnSaveToDB_Click(sender As Object, e As EventArgs) Handles btnSaveToDb.Click, btnSaveToDb.Click
and so on. What's really strange is that the code would then be executed twice! I am using the code to write data from one table to another and was puzzled by why twice the number of records as I expected was being saved. It took a while before I saw the
My question is why is this behaviour occurring and how do I prevent it?
Thanks for your help.
Mar 30, 2016 02:17 PM|DeadTroll|LINK
restart visual studio and remove the extra handles code for the same button.
Mar 31, 2016 07:57 AM|Candice Zhou|LINK
You should make sure that your page directive at the top has the correct filename, and its CodeFile attribute to correctly map to an existing code behind file.