如何在页面重新加载时防止多次保存? [英] How to Prevent Saving Multiple Times on Page Reload?

查看:123
本文介绍了如何在页面重新加载时防止多次保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..



我有一个包含gridView和Save Button的Asp.net页面。

所以,这里选择的很少行和单击保存将保存在数据库中。

保存当我点击页面重新加载它将保存多次。

那么,我如何防止多次保存。





提前感谢你..

Avinash

解决方案

你可以把条件放在你的查询中,比如

Ex。

如果不存在(从table1中选择col1,其中col1 = @ col1)
开始
插入table1(col1)值(@ col1)
结束


你能粘贴你的吗?代码?



作为建议,在保存到DB之前检查是否选择了任何行,保存后也清除选择。


< blockquote>你必须实现 PRG模式以避免上述问题。请阅读以下链接了解更多信息。



PRG:

什么是PRG模式?

PRG代表发布/重定向/获取

而不是直接返回HTML页面,

POST操作返回一个重定向命令(使用HTTP 303响应代码(有时是302)和HTTPLocation响应头),

指示浏览器使用HTTP GET请求加载不同的页面

然后可以安全地将结果页面加入书签或重新加载而不会出现意外的副作用



重定向后 - 使用ASP.NET获取

Hi..

I have one Asp.net Page that contains gridView and Save Button.
So,here am selecting few rows and Click on Saving it will Save in Database.
while Saving When i click on Page reload it will Saving Multiple Times.
So, How do i prevent Saving Multiple times.


Thanking You in Advance..
Avinash

解决方案

You can put condition inside your query like
Ex.

if not exists(select col1 from table1 where col1=@col1)
begin 
  insert into table1(col1)values(@col1)
end


Can you paste your code?

As a suggestion, check if any row is selected or not before save in DB , also clear selection after save.


You have to implement PRG pattern to avoid above issue.Please read below link for more info.

PRG:

What is the PRG Pattern ?
PRG stands for "Post/Redirect/Get"
Instead of returning an HTML page directly,
The POST operation returns a redirection command (using the HTTP 303 response code (sometimes 302) together with the HTTP "Location" response header),
Instructing the browser to load a different page using an HTTP GET request
The result page can then safely be bookmarked or reloaded without unexpected side effects


Post-Redirect-Get with ASP.NET


这篇关于如何在页面重新加载时防止多次保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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