locked
Double clicking on button in design view produces wierd behaviour RRS feed

  • Question

  • User411346422 posted

    Hello,

    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:

    <VB>

    Protected Sub btnSaveToDB_Click(sender As Object, e As EventArgs) Handles btnSaveToDb.Click

    </VB>

    Double-clicking on the button in design view, however, produces this:

    <VB>

    Protected Sub btnSaveToDB_Click(sender As Object, e As EventArgs) Handles btnSaveToDb.Click, btnSaveToDb.Click

    </VB>

    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 problem.

    My question is why is this behaviour occurring and how do I prevent it?

    Thanks for your help.

    Wednesday, March 30, 2016 8:13 AM

Answers

  • User614698185 posted

    Hi mojo99,

    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.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 31, 2016 7:57 AM

All replies

  • User37182867 posted

    restart visual studio and remove the extra handles code for the same button.

    Wednesday, March 30, 2016 2:17 PM
  • User614698185 posted

    Hi mojo99,

    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.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 31, 2016 7:57 AM