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