Solution to prevent repeated page submissions and insert duplicate data

Source: Internet
Author: User
ArticleDirectory
    • Problem
    • The final solution utilizes the unique ID feature.
Problem

When a user clicks the charge button in the newly-developed property charging system, if the user clicks the charge button multiple times, two receiving orders will be generated. If the user finds a problem, he will pass

Http://www.cnblogs.com/happyhippy/archive/2010/08/15/1800289.html

Added

Lnkcharge. attributes [ " Onclick " ] =   This . Getpostbackeventreference ( This . Lnkcharge) +   " ; This. Disabled = true; " ; // Prevent repeated submission

The local machine passed the test, but the user still had repeated receipts the next day...

The final solution utilizes the unique ID feature.

I feel that this kind of control is not very safe on the client, so I put the solution in the background.CodeBut the buttons at the front end still have

Because the table we created is ID using guid, we can go to the page! Ispostboack generates a temporary guid and stores it in viewstate.

If ( ! Ispostback)
{
Tempid = Guid. newguid (). tostring ();

Then, use the guid as the ID when inserting the receipt ticket data in the billing button event. Because the ID cannot be repeated, the duplicate guid will not be inserted.

It is recommended to determine whether the guid already exists before the current insertion.

Model. collectioninfo collection =   New Model. collectioninfo ();
Collection. ID =   New GUID (tempid ); If (New BLL. bcollection (). getcount (new model. searchclass. collectionsearch (). Id (tempid)> 0)
{
Scriptalert ("the billing items on this page have been charged and cannot be charged repeatedly ");
Return;
}
Guid collectionid = guid. empty;
Try
{
Collectionid = new BLL. bcollection (). insert (Collection );
}
Catch
{
Scriptalert ("the billing items on this page have been charged and cannot be charged repeatedly ");
Return;
}

 

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.