1

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:

enter image description here

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

user3122306
  • 245
  • 2
  • 4
  • 15

1 Answers1

2

When PageIndex is clicked, it postbacks the page, i.e. equivalent to form submission. So when you refresh, it agains posts page, and asks Confirm Form Re-submission.

This is equivalent to this scenario. -- Preventing form resubmission

Submit a form, and after submission , refresh the page, it will ask same message. And this is the default behavior of browser.

It has nothing to do with your grid paging or the paging click in it. It gets' fired by the browser to prevent the user from repeating the form submission as it posts entire grid data.

Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
  • so...Are you saying that web browser behaviour its 'normal' and can not be by-passed? :( – user3122306 Oct 15 '14 at 11:41
  • 1
    Yes, Refresh means re postback, so browser behaves like this – Arindam Nayak Oct 15 '14 at 11:42
  • you can put the grid and the page numbers on updatepanel I guess, though its not that much good for performance but it feels good – Sandip Bantawa Oct 15 '14 at 11:48
  • adding more info to this, since it will be updatepanel, it will still post data but, it will do that via `ajax`, so when F5 is hit, there won't be any browser page postback ( as this is done via ajax) , so no message will be shown. – Arindam Nayak Oct 15 '14 at 11:55
  • any idea how to disable this message box and just directly allow re submission without confirmation? – Muhammad Saqib Aug 20 '18 at 17:11
  • @MuhammadSaqib, instead of gridview use ajax version of any tabular data, there should some JS library which does all these ( like kendo from telerik). – Arindam Nayak Aug 21 '18 at 06:48