问题表单单击浏览器的刷新按钮比再次单击btn click事件触发 [英] problem form click refresh button of browser than again btn click event fire

查看:75
本文介绍了问题表单单击浏览器的刷新按钮比再次单击btn click事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览器的问题表单单击刷新按钮比btn click事件触发再次.
我的问题是,当我单击按钮而不是表单提交按钮时,相应的方法将运行并返回到我的页面.aspx.当我单击浏览器的刷新按钮时,它将再次发布表单和提交方法,这将导致我的数据库管理被破坏. 我也想使用其他参数再次提交表单,但不希望使用浏览器刷新按钮.
如何停止刷新按钮以重新提交我的表单.
请给我一些代码,因为我阅读了更多有关resubmit的文章.原因是浏览器具有历史记录并保持状态,但是服务器不保持其状态等.





黎兹汗

problem form click refresh button of browser than again btn click event fire .
my problem is this when i click button than form submit and respective method will run and return back into my page .aspx when i click refresh button of browser than it again post form and submit method would call for this my data base management is destroyed. also i want to submit form again with another parameter but not for browser refresh button .
how to stop refresh button to resubmit my form .
please give me some code because i read more article about resubmit.cause like browser have history and maintain state but server not maintain its state etc.





Rizwan khan

推荐答案



我认为您无法避免单击浏览器的刷新按钮时加载表格.
相反,您可以使用页面的"IsPostBack"属性.

区别在于,当您单击刷新按钮时,值为"IsPostBack = false",但如果单击按钮为"IsPostBack = true".

因此在执行代码之前,您可以检查"IsPostBack"属性的值并相应地放置代码.

http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx [ ^ ]

希望对您有所帮助.
Hi,

I think you cannot avoid form to load on click of refresh button of the browser.
instead you can make use of "IsPostBack" property of the page.

The difference is when you click on refresh button, then value of "IsPostBack=false", but if click on button, "IsPostBack=true".

so before excecuting your code, you can check the value of "IsPostBack" property and place the code accordingly.

http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx[^]

hope it helps.


这是由于浏览器的工作方式所致.首次发布页面时,浏览器发送所有数据,然后返回HTML进行渲染.如果您单击刷新(F5),则浏览器将重新发送上一个POST请求,从而再次发送信息.这导致记录重复.需要为此类场景/页面应用Post-Redirect-Get模式,在HTTP Post之后,而不是返回HTML,而是重定向返回页面(相同或不同).

万一您不能重定向或对重定向不满意,请查看以下文章:
ASP.Net中的刷新页面问题 [提交请求后,请刷新 [检测页面刷新 [
This is due to how browsers work. The first time you POST the page, the browser sends all the data, then returns back HTML to render. If you hit refresh (F5) then the browser re-sends the last POST request thus re-sending the information again. This causes duplication of record. One need to apply Post-Redirect-Get pattern for such scenarios/pages, where after an HTTP Post, instead of returning HTML, is redirected back to a page (either the same or another).

In case, you cannot redirect or not comfortable with redirect, have a look at these articles:
Refresh Page Issue in ASP.Net[^]
Stop Refresh after Submitting your Request[^]
Detecting Page Refresh[^]


这篇关于问题表单单击浏览器的刷新按钮比再次单击btn click事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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