Webforms刷新问题 [英] Webforms Refresh problem

查看:72
本文介绍了Webforms刷新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于每个WebForms开发人员来说,这可能是一个简单的问题,但是我对此很了解.我的页面上有一个"ADD"按钮,这会导致一个jQuery弹出窗口,用户可以在其中提交一个表单,该表单将为页面上的转发器添加一个条目.我的问题是,用户添加项目后,如果他们再单击刷新按钮,则该项目将再次添加.我无法使用page.ispostback停止此操作,因为那样会阻止原始添加.我在这里可以做什么?

This is probably a simple question for every WebForms developer but I am knew to this scene. I have a page that has an "ADD" button on it that results in a jquery popup where the user can submit a form that will add an entry to the repeater on the page. My problem is that after the user adds an item, if they then hit the refresh button the item will get added again. I can't stop this with the page.ispostback because that would block the original add. What can I do here?

推荐答案

这是一个常见问题.这是该问题的解释和解决方案.

that's a common problem. Here's explanation and solution of the problem.

当通过HTTP POST请求将Web表单提交到服务器时,尝试刷新某些用户代理中的服务器响应的Web用户可能导致重新提交原始HTTP POST请求的内容,从而可能导致不良结果,例如重复的网上购买. 为了避免此问题,许多Web开发人员都使用PRG(发布/重定向/获取)模式.

When a web form is submitted to a server through an HTTP POST request, a web user that attempts to refresh the server response in certain user agents can cause the contents of the original HTTP POST request to be resubmitted, possibly causing undesired results, such as a duplicate web purchase. To avoid this problem, many web developers use the PRG(Post/Redirect/Get) pattern.

从Wiki复制( LINK )

最简单的解决方案可以是 Response.Redirect 到同一页面(即,如果您的页面名为default.aspx,请写Response.Redirect("default.aspx")).如果您执行此操作,则浏览器的刷新"按钮将仅加载页面,就像您在地址栏中输入URL并导航到该页面一样.

simplest solution can be Response.Redirect to the same page (i.e. if you page is named default.aspx write Response.Redirect("default.aspx")). if you do this browser refresh button will just load the page as if you have typed in address bar URL and navigated to it.

这里有一个问题如何阻止不想要的回发,这可能也很有用.

here's SO question How to stop unwanted postback that might be useful as well.

这篇关于Webforms刷新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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