简体   繁体   English

当用户按F5或刷新页面时,Web浏览器显示警告“确认表单重新提交”

[英]Web Browser display a warning 'Confirm Form Resubmission' when user press F5 or refresh the page

I have a very simple asp page: 我有一个非常简单的ASP页面:

Default.aspx: 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: Default.aspx.cs的代码隐藏:

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: 如果用户按F5键或刷新GridView页面索引2中的页面,则Web浏览器会弹出以下消息:

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) (并显示GridView页面索引'n',而不会弹出任何网络浏览器警告)

PS: Tested with Chrome, Firefox and IE11 PS:经过Chrome,Firefox和IE11测试

When PageIndex is clicked, it postbacks the page, ie equivalent to form submission. 单击PageIndex ,它将回发页面,即等同于表单提交。 So when you refresh , it agains posts page, and asks Confirm Form Re-submission . 因此,当您refresh ,它会再次发布页面,并要求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. 它会被浏览器触发,以防止用户在发布整个网格数据时重复提交表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM