Data | Repeat-submit this article from the grammatical point of view, the original author should be translated from somewhere.
Simple solution:
The easiest way to do this is to use the Response.Redirect ("Selfpage") statement in the code of your server-side control when the user submits it. But most of the numbers include me not using this method.
Multiple submissions:
Please note: This article is not about how to prevent multiple submissions on a page. This article is to teach you how to prevent a page from refreshing after submitting a request. The situation is that when the user submits the button, the end user can no longer click the Submit button. However, the end user can still submit the data by clicking on the browser's refresh button. If you want to prevent multiple submissions you can go to http://metabuilders.com/on the Internet to find some information, where there is a submission control can be used.
General Solutions
The usual workaround is to store the ID of the session and compare the SessionID stored in the viewstate when submitting to prevent users from refreshing the screen. The premise is that your program allows automatic postbacks, and if not, you'll have to store the variable in the hidden field. A typical example is given below. In the Page_Load event, you store the SessionID and a timestamp for the first commit.
protected System.Web.UI.WebControls.Button Submitbutton;
protected System.Web.UI.WebControls.Label Refreshid;
private void Page_Load (object sender, System.EventArgs e)
{
if (RefreshID.Text.Length = 0)
{
Refreshid.text = Session.sessionid+datetime.now.ticks.tostring ();
}
}
private void Button1_Click (object sender, System.EventArgs e)
{
String sestoken = (string) Session[frameworkconst.sync_control_keyword]; string pagetoken = Refreshid.text;
if (Sestoken!= null && sestoken!= pagetoken)
{
Response.Write ("The" the "the Refresh was performed to submit.");
}
Else
{
Do your processing avoid Refresh trap
Response.Write ("The processing is done here.") disabling submit
button so this user can not perform multiple submit. ");
Response.Write ("But still user can peform Refresh on page.");
}
Session[frameworkconst.sync_control_keyword] = session.sessionid+datetime.now.ticks.tostring ();
Refreshid.text = Sestoken;
submitbutton.enabled = false;
}
A different solution:
Fortunately, ASP.net offers some simpler ways. The disadvantage of the solution above is that we have to decide some logical problems ourselves in the event of the control button. Imagine that if you had hundreds of pages to submit in your solution, you would have to write a number of such logic. The custom Web control and HTTP modules provide the same workaround. You can put this control on the page you need to control and it will work. Of course, not all situations are needed, such as a search page that allows users to refresh. However, the control refresh button is absolutely necessary when there is an action to insert, update, and delete the database in the page.
Let's take a look at how the above program works.
First step: You need to register the HTTP module module in the system.web section.
<add name= "Synchttpmodule" type= "EAD". Controller.synchttpmodule, Sync "/>
The second step: in the page control page to put our developed controls.
Working principle:
It works in the same sense as the usual one. But here's a generic approach. This provides a common way. In my opinion, if you have some good patterns, it will greatly speed up your development.
We need to store the tokens in the session at the first commit and compare them to each other at the time of the request. With HTTP handler, we store tokens in the session. There is such an event PreRequestHandlerExecute we can find the session through it, if it is the other event, the session does not exist, such as the BeginRequest event. Compare the values of both in this event, and if the difference is the refresh event. At this point you can add your own processing methods, I generally will be turned to a page to tell the user can not repeatedly submit.
private void Onprerequesthandlerexecute (object source, EventArgs e)
{
HttpContext context = ((HttpApplication) source). context;
string _keyword = Frameworkconst.sync_control_keyword;
String sestoken = (string) context. Session[_keyword];
String Reqtoken = context. Request.params[_keyword];
Save session and tagged values if no submissions have been submitted
if (Reqtoken!= Frameworkconst.bypass_sync_keyword)
{
Context. Session[_keyword] = context. Session.sessionid+datetime.now.ticks.tostring ();
}
if (Reqtoken!= null && reqtoken!= sestoken)
{
String Path=context. request.applicationpath+
& "/common/synccontrol.aspx?returnurl=" +
&context. Request.Url.AbsolutePath;
Context. Server.Transfer (path);
}
}
The Synccontrol control will establish a hidden input field to save the session set in HTTP module.