Webforms 刷新问题

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

问题描述

对于每个 WebForms 开发人员来说,这可能是一个简单的问题,但我对这个场景很熟悉.我有一个页面上有一个添加"按钮,它会导致一个 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(Post/Redirect/Get) 模式.

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.

从维基复制(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.

这里是 SO 问题 如何停止不需要的回发,这也可能有用.

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)