[英]Resubmission on load asp.net c#
I am working on a C# project using asp framework 4.5 and I am having this problem : 我正在使用ASP框架4.5进行C#项目 ,但遇到了这个问题:
I want a way to avoid a resubmission of the form on page refresh (without self redirect): 我想要一种避免在页面刷新时重新提交表单的方法(无自重定向):
When refreshing the page, the button does trigger itself, I need to avoid the second submission without page redirection . 刷新页面时,按钮会触发自身,我需要避免在没有页面重定向的情况下进行第二次提交。 I am trying to upload a file, on the first try every thing is Working fine, but, when I hit
f5
to refresh the page, the form will be resubmitted. 我正在尝试上传文件,第一次尝试时一切正常,但是,当我按
f5
键刷新页面时,将重新提交表单。
try below code 尝试下面的代码
public bool IsPageRefresh = false;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["postids"] = System.Guid.NewGuid().ToString();
Session["postid"] = ViewState["postids"].ToString();
}
else
{
if (ViewState["postids"].ToString() != Session["postid"].ToString())
{
IsPageRefresh = true;
}
Session["postid"] = System.Guid.NewGuid().ToString();
ViewState["postids"] = Session["postid"].ToString();
}
}
just check below condition on button click 只需检查以下条件,单击按钮
if (!IsPageRefresh)
{
// write you post code
}
try this it's working perfect for me . 试试这个,对我来说很完美。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.