刷新/重新加载ASP.net的副作用? [英] Refreshing/Reloading side effect with ASP.net?

查看:88
本文介绍了刷新/重新加载ASP.net的副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web&处相对较新. ASP.Net开发,请多多包涵.在测试我们的网页的过程中,我注意到,如果用户单击刷新/重新加载",并在重新发送信息"对话框中出现提示时单击重试",则无论用户选择之前触发的最后一个事件设为刷新",随后将再次被触发.
例如,我们具有上一个"和下一个"导航按钮,允许用户浏览一系列问题.如果操作员点击刷新/重新加载",则用户最后按下的导航按钮将再次触发.这实际上是有道理的,但是最终的结果是用户最终进入了以前查看过的下一页或上一页.是否有解决此类问题的方法?

I'm relatively new at web & ASP.Net development, so bear with me. In the course of testing our web pages, I noticed that if a user were to click "Refresh/Reload", and clicks "Retry" when prompted on the "Resend Info" dialog box, whatever last event that was fired before the user chose to "Refresh", will subsequently be fired again.
As an example we have "Previous" and "Next" Nav buttons which allows a user to navigate through a series of questions. Should the operator hit "Refresh/Reload", which ever Nav button the user pressed last will fire again. This actually makes some sense, but the net effect is the user ends up on the next or previous page from which he was formerly viewing. Is there a work around for this sort of thing?

推荐答案

这是由于您处理

This is due to the way you are handling PostBacks.

需要一点背景知识:

网络是无状态的",这意味着从客户端到服务器的每个请求都独立于其之前或之后的请求.没有保持状态".如果您查看HTTP级别,它只是发送到服务器的一个文本Blob,上面写着向我发送此信息",然后服务器将其发送回去.没有我是3分钟前在这里的同一用户,我想从上次我们讲话时的页面移到下一页".

The web is "stateless", which means each request from a client to a server is independent of the request before it or the request after it. There is no "state" maintained. If you look at the HTTP level, it's simply a text blob sent to the server that says "send me this information" and the server sends it back. There's no "I am the same user who was here 3 minutes ago and I would like to move to the next page from the one I was on last time we spoke".

ASP.NET解决此问题的方法是使用ViewState和回发.每次您单击ASP.NET按钮时,它实际上是在提交一个表单,该表单具有一个包含一堆编码数据的隐藏字段.该数据包含服务器重建"页面状态所需要的所有信息,这是上次访问时的信息.然后,它可以执行移至下一页",该命令才有意义.当ASP.NET将HTML发送回客户端时,它将使用新数据更新该隐藏字段,再次代表页面的状态,如现在.下次单击任何按钮时,将再次发送数据,再次重建页面,并重复该循环.

The way ASP.NET solves this problem is using ViewState and postbacks. Every time you click an ASP.NET button, it is actually submitting a form which has a hidden field with a bunch of encoded data. That data contains all of the information the server needs to "reconstruct" the state of the page as it was the last time it. Then it can execute the "move to next page" and that command makes sense. When ASP.NET sends the HTML back to the client, it updates that hidden field with new data, again representing the state of the page, as it is right now. And the next time you click any button, the data is sent again, the page is reconstructed again and the cycle repeats.

当用户点击刷新"时,浏览器会询问他们是否要重新提交表单.他们正在重新提交与上一轮相同的数据.

When the user hits "refresh" the browser asks them if they want to re-submit the form. They are resubmitting the same data they did last time round.

对您的影响:

如果您尝试独立于ASP.NET ViewState来跟踪有关用户或其正在执行的操作的任何数据,则需要确保每次页面处理时都进行同步.

If you attempt to track any data about the user or what they are doing independently of the ASP.NET ViewState, you will need to make sure you synchronize that each time the page processes.

您可能希望将当前页面"保留在ViewState中:

You probably want to keep the "current page" in ViewState:

ViewState.Add("CurrentPage", intCurrentPage);

因此,当您调用MoveNext事件处理程序时,可以确保您相对于页面是在上次发送到客户端时相对于页面移动.

So when you call the MoveNext event handler, you can be sure you are moving relative to the page as it was the last time it was sent to the client.

这篇关于刷新/重新加载ASP.net的副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆