Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.Net 2.0:浏览器后退按钮-回发或回调参数无效_Asp.net_Ajax_Gridview_Postback - Fatal编程技术网

ASP.Net 2.0:浏览器后退按钮-回发或回调参数无效

ASP.Net 2.0:浏览器后退按钮-回发或回调参数无效,asp.net,ajax,gridview,postback,Asp.net,Ajax,Gridview,Postback,我有一个简单的页面,在初始加载时,它将数据绑定到GridView。此gridview启用了排序和分页功能,并由UpdatePanel包围 当用户执行以下操作时,我收到此错误: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventV

我有一个简单的页面,在初始加载时,它将数据绑定到GridView。此gridview启用了排序和分页功能,并由UpdatePanel包围

当用户执行以下操作时,我收到此错误:

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
其中,gvResults是GridView,“SearchResults”是存储在viewstate中的列表

编辑

虽然当用户返回页面(返回到第1页)时,gridview没有显示第5页,但出于某种原因,浏览器确实保存了viewstate,并在第5页显示了gridview。因此,如果我点击第4页并查看分页事件的代码,我可以看到它认为它所在的页面是5。。。即使显示的内容是第1页


这个故事的寓意显然是,当用户单击“后退”按钮返回页面时,viewstate被保存,但显示的表却没有保存。

发生的事情正是错误所说的——用户在单击“后退”按钮后尝试使用的控件不是原始控件,因为它是从缓存加载的。这可以通过你那里的易变数据或者时间戳来识别——我不知道

你能做的就是

<%@ Page EnableEventValidation="false" %>


在那一页上,让我们知道这是否有效,以及它是否破坏了你页面上的其他内容…

在搜索之后,我真的找不到合理的答案;但是,我发现您可以使用3.5预览控件w/asp.net 2.0,因此我将历史记录控件添加到页面中,并让它处理后退按钮问题

看来问题解决了


谢谢

此错误与浏览器中的缓存内容有关。因此,解决方案是不允许在浏览器中缓存此页面:

        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.Cache.SetExpires(DateTime.Now)

那就行了;但是我不想关闭验证。如果有其他方法解决这个问题,根据该页面上的流量,您可能需要找到另一种解决方案,因为停止缓存可能会很快成为一条不好的道路。
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.Cache.SetExpires(DateTime.Now)