The most common solution to this problem on the Internet is not to save the cache, that is, after the submission, the data in the form will not be cached and saved by the browser. If you encounter a refresh or rewind request again, the page will display "the web page has expired", and the data will not be submitted repeatedly, which is effective in preventing refresh and repeated submission.
The following uses a simple post as an example to describe how to disable cache to prevent repeated submission refresh. The form data includes two parts: "title" and "body.
The method is as follows:Code(Post. aspx ):
// Page loading
Protected void page_load (Object sender, eventargs E)
{
// When loading a page, you can set the page cache to "setnostore ()", that is, no cache.
Response. cache. setnostore ();
// The variable "issubmit" stored in the session indicates whether the submission is successful.
If (bool) session ["issubmit"])
{
// If the form data is submitted successfully, set "session [" issubmit "]" to false.
Session ["issubmit"] = false;
// Display the submitted information
Showmsg. Text ="* Submitted successfully!";
}
Else
// Otherwise (no submission or page refresh), no information is displayed
Showmsg. Text = "";
}
// Click the event button (btnok ).
Protected void btnok_click (Object sender, eventargs E)
{
If (txttitle. Text. tostring (). Trim () = "")
// Showmsg is used to display the prompt information
Showmsg. Text ="* The title cannot be blank!";
Else if (txttext. Text. tostring (). Trim () = "")
Showmsg. Text ="* The content cannot be blank!";
Else
{
// Submit the data to the database.
// After the submission is successful, set "session [" issubmit "]" to true
Session ["issubmit"] = true;
// Forcibly convert the page (not required, otherwise refresh will be submitted again and still go to this page ),
The data submitted in the cache is released through page conversion, that is, the submitted bidding data is not saved to the cache,
If you move back, the page cannot be displayed.
Response. Redirect ("post. aspx ");
}
}