About page refresh, event repeat submission method sharing _ Related Tips

Source: Internet
Author: User
Browser refresh is to repeat the last request sent to the server, and the ASP.net server control's events are sent to the server through the postback mechanism. So, when you click the Submit button and then refresh, you are actually sending the postback request to the button again. The asp.net application server is not able to distinguish whether this is a normal click button to add or F5 refresh Add (this involves the page life cycle ...). ), this results in the presence of N-identical data in the database.
In the process of solving this problem, try a few ways:

(1) After the event is submitted, the parameters are empty, so that the program in the execution process, because there is no parameters and do not do business processing. This approach has no effect, because the server executes the last requested event, and after the event is committed, changing the parameter has no meaning.

(2) After the event is submitted, redirect the page to the current page (Response.Redirect ("/basedata/pictureadd.aspx", true); Because each page has its own lifecycle, after redirection, the current page operation ends. This method works!

Why do not encounter such problems in the original ASP development program? I think it is because the ASP program is mainly to submit the form to another page processing, and, after the page processing, will jump to another prompt page. In an ASP program, you can effectively avoid duplicate submissions by simply setting the page to expire at rollback time. But in ASP.net, basically all operations are based on event operations, and the event is essentially the page itself submitted to itself, and the page does not recognize the commit when the normal operation or repeat refresh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.