Asp.Net SQL Refresh page duplicate inserts?

前端 未结 4 1709
悲哀的现实
悲哀的现实 2021-01-24 16:51

I have a *.aspx page that contains a text box and a button. When the user enters information in to the textbox and clicks post, it inserts the data into my sql database. The iss

4条回答
  •  自闭症患者
    2021-01-24 17:34

    If the PostButton_Click is the server handler for the click event on your button then insert code shold be executed only if the user hits the post button - it should not happen in case of refresh.

    I am pretty sure is not enough - to be sure put a breakpoint in your PostButton_Click method, hit F5 to run in debug mode and see if the breakpoint gets hit with a refresh.

    If so it means that:

    1. you are calling explicitly PostButton_Click from somewhere else (Page_Load?)
    2. PostButton_Click was accidentally set as event handler for some other event on the page

    A quick way of verifying hypotesis 1 & 2 is to run a search for PostButton_Click and see where you are calling it from or if it set as handler for some other element (maybe your form?) in the markup.

提交回复
热议问题