I have a very simple asp page:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AllowPaging="true" PageSize="4"
OnPageIndexChanging="GridView1_PageIndexChanging">
</asp:GridView>
</div>
</form>
</body>
</html>
Default.aspx.cs code-behind:
public partial class _Default : System.Web.UI.Page
{
private class FakeData
{
public string Name { get; set; }
public int Age { get; set; }
}
private List<FakeData> fakeData;
void InitFakeData()
{
fakeData = new List<FakeData>()
{
new FakeData(){ Age = 8, Name = "John"},
new FakeData(){ Age = 9, Name = "Carl"},
new FakeData(){ Age = 7, Name = "June"},
new FakeData(){ Age = 6, Name = "Ellie"},
new FakeData(){ Age = 9, Name = "Betty"},
new FakeData(){ Age = 10, Name = "Sam"},
new FakeData(){ Age = 5, Name = "Peter"},
};
}
void ShowData()
{
InitFakeData();
GridView1.DataSource = fakeData;
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
ShowData();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
ShowData();
}
}
Result:
The problem:
If the user press F5 or refresh the page in GridView Page Index 2 the web browser pop-ups the following message:
Confirm Form Resubmission The page you 're looking for used information that you entered . Back to repeat could result in some action. Do you want to continue?
Question:
How can you avoid the browser to display that message? (and show the GridView Page Index 'n' without any web browser warning pop-up)
PS: Tested with Chrome, Firefox and IE11