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