The ASPNET webpage prevents duplicate submissions by backing up or refreshing

Source: Internet
Author: User

The ASPNET webpage prevents duplicate submissions by backing up or refreshing


Set up a website has two pages, the first page after the submission to the second page, when using the browser's back function, the browser will render the first page again, which may occur duplicate submissions, in addition, after going to the second page, refresh the browser, will return to the first page, also can cause duplicate submissions.

Ideally, when the first page is submitted to the second page, then, such as using the browser's fallback function, the browser renders the first page, when submitted, the "page has expired" prompt, and no longer commit to jump, and so on, or go to the second page, refresh the browser, the "page is out of date" prompt.

Now provides a simple method, the sample code is as follows:


<%@ page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "Norepearsubmit.webform1"% ><! DOCTYPE html>



Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using              System.web.ui.webcontrols;namespace norepearsubmit{public partial class WebForm1:System.Web.UI.Page { protected void Page_Load (object sender, EventArgs e) {if (!                IsPostBack) {label1.visible = false;                    if (session["isform1valid"] = = null) {session["isform1valid"] = "true"; Next to initialize code} else {if (session["Isform1valid"]. ToString () = = "false") Label1.visible = true;//Refresh}}} protected Voi D Button1_Click (object sender, EventArgs e) {if (session["Isform1valid"]. ToString () = = "true") {//////\ Normal code at this location///Sess        ion["isform1valid"] = "false";        Server.Transfer ("webform2.aspx");            } else {label1.visible =true; }        }    }}
is not very simple, the point is that the Web page commits to execute the Page_Load method, in the above code described in the page, the button is clicked, first executes the Page_Load method before executing
The Button1_Click method, and the value of IsPostBack at this time is true. The first time you open a Web page or refresh the browser, the Page_Load method is also executed, and the value of IsPostBack is false at this time.

The ASPNET webpage prevents duplicate submissions by backing up or refreshing

Related Article

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.