Methods To prevent page refreshing and submission

Source: Internet
Author: User

The method for checking whether the page is sent back by clicking the submit button is IsPostBack. Sometimes we need to check whether a page has been repeatedly refreshed to prevent repeated data submission. Of course, there are many judgment methods. Here I will briefly describe a simple and easy-to-understand method-to use Session for check (because the Session is placed on the server, in addition, when loading the access page for the first time, you can make a record, and then directly judge whether the Session in the page is null. If it is not null, it indicates that the page has been refreshed ). Here is the code:
[C #]
Public class MyPage: Page
{
Public bool IsRefresh {get; set ;}
Protected override void OnInit (EventArgs e)
{
Base. OnInit (e );
If (Session ["flag"] = null)
{
Session ["flag"] = true;
IsRefresh = false;
}
Else
{
IsRefresh = true;
}
}
}

[VB. NET]
Public Class MyPage
Inherits Page
Public Property IsRefresh () As Boolean
Get
Return m_IsRefresh
End Get
Set
M_IsRefresh = Value
End Set
End Property
Private m_IsRefresh As Boolean
Protected Overrides Sub OnInit (e As EventArgs)
MyBase. OnInit (e)
If Session ("flag") Is Nothing Then
Session ("flag") = True
IsRefresh = False
Else
IsRefresh = True
End If
End Sub
End Class

It is mainly to customize a MyPage class, Inherit System. Web. Page, and overwrite the OnInit method to set whether the Session identifier is loaded for the first time. If other pages need to be used, simply inherit the my Page method and use the IsRefresh attribute to determine.
 

From Serviceboy

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.