新行插入每一页刷新 [英] New row inserted for each page refresh

查看:98
本文介绍了新行插入每一页刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我同时插入记录到数据库中得到一个奇怪的问题。
在我的按钮点击事件,我试图插入一些值到我的数据库是工作的罚款。一旦插入完成......再次,如果我preSS F5或刷新一个新行越来越与表中的previous值插入浏览器。

Hi I'm getting a strange problem while inserting records into database. In my button click event I'm trying to insert some values into my database it is working fine. Once insertion is completed... again if I press F5 or refresh the browser a new row is getting inserting with the previous values in the table.

为什么它是怎么回事?

感谢您

推荐答案

当您单击该按钮,它发送一个POST请求到服务器,并且更新的页面被送回作为响应。为了刷新页面,同一职位,必须再次发出,并且服务器间$ P $点这是另一次按鼠标。

When you click the button, it sends a POST request to the server, and the updated page is sent back as the response. In order to refresh that page, the same POST must be made again, and the server interprets this as another button click.

大多数Web浏览器给在这种情况下一个警告,说刷新页面可以重复刚刚执行的任何操作(在你的情况下,插入数据库的行)。但是,如果你想从发生在所有prevent这一点,最好的办法可能是与重定向POST请求作出回应。在用C#ASP.NET,要做到这一点的方法是:

Most Web browsers give a warning in this situation, saying that refreshing the page may repeat any action that was just performed (in your case, inserting a row in the database). But if you want to prevent this from happening at all, the best way is probably to respond to the POST request with a redirect. In ASP.NET with C#, the way to do this is:

Response.Redirect(url);

重定向回到同一页是罚款,或者你也可以重定向到另一个页面。当浏览器收到此重定向,它会发出指定的页面GET请求。然后,如果你刷新,不将采取行动。

Redirecting back to the same page is fine, or you could also redirect to a different page. When the browser receives this redirect, it will issue a GET request for the specified page. Then if you refresh, no action will be taken.

这篇关于新行插入每一页刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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