单击刷新按钮时如何禁用回发 [英] How to disable PostBack when we click refresh button

查看:122
本文介绍了单击刷新按钮时如何禁用回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Webform上有一个文本框,提交按钮和网格.

当我单击提交"按钮时,它将为网格添加文本框的值.

问题是如果我按F5之后再次将其提交到网格.

我如何避免这种情况.

There is one textbox,submit button,grid on webform.

When i click on submit button it will add value of textbox to grid.

Problem is if i press F5 after that it again submit to grid.

How do i avoid that.

推荐答案

除上述答复外,请查看以下文章:
ASP.Net中的刷新页面问题 [提交请求后,请刷新 [检测页面刷新 [
Apart from replies above, have a look at these articles:
Refresh Page Issue in ASP.Net[^]
Stop Refresh after Submitting your Request[^]
Detecting Page Refresh[^]


将页面重定向回自身,然后刷新将执行重定向,而不是回发.
Redirect your page back to itself, then the refresh will do the redirect, not the postback.


想要一个简单的工作解决方案吗?
多次单击按钮等可以完美地实现这一目标.
http://csharpdotnetfreak.blogspot.com/2008/12/detect- browser-refresh-to-avoid-events.html
PS.不,这不是我的解决方案的广告,只想提供帮助

Want a simple working solution?
This one works perfectly with multiple clicks on button and so on.
http://csharpdotnetfreak.blogspot.com/2008/12/detect-browser-refresh-to-avoid-events.html
PS. No it''s not an ad for my solution, just want to help

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["CheckRefresh"] =
Server.UrlDecode(System.DateTime.Now.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["CheckRefresh"].ToString() ==
ViewState["CheckRefresh"].ToString())
{
Label1.Text = "Hello";
Session["CheckRefresh"] =
Server.UrlDecode(System.DateTime.Now.ToString());
}
else
{
Label1.Text = "Page Refreshed";
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
ViewState["CheckRefresh"] = Session["CheckRefresh"];
}
}


这篇关于单击刷新按钮时如何禁用回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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