为什么页面在刷新时会在数据库中插入值? [英] why page inserts the value in database while refreshing?

查看:73
本文介绍了为什么页面在刷新时会在数据库中插入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在点击按钮时在数据库中插入值。之后,当我刷新页面时,它再次在数据库中插入值。我不希望这种情况发生。

i am inserting values in database on click of the button. after that when i refresh the page it again inserts the values in database. i dont want this to happen.

推荐答案

检查这个

在ASP.NET中检测刷新或回发 [ ^ ]


引用:

所有在回发后被触发的服务器端事件也会在刷新时被触发,但幸运的是存在一个事件,即onsubmit,只有当有一个真正的回馈请求。这是表格的客户端事件放在您的网页上。

All server-side events that get fired on the post-back get fired on refresh also, but fortunately there exists one event, onsubmit, that only gets fired when there is a genuine post-back request. It is the client-side event of the form placed on your web page.


您好,



< b>在任何事件之后,如果你刷新页面然后它会提示它,如果我们允许它重做上一次活动。



现在在你的情况下你正在db中插入值。所以在重新刷新页面时你的数据库插入查询会触发,它会在db中插入值。



现在你有两种方法可以解决这个问题。

1。将db值重定向插入同一页面后。

Hi,

After any event, if you refresh page then it prompt for it and if we allow it it redo last event.

Now in your situation you are inserting values in db. So on refreshing page again your db insert query fires and it insert value in db.

Now you have two ways to over come this.
1. After inserting db value redirect to same page.
e.g. //your db code
     Response.Redirect(Request.Url.AbsoluteUri);



2。在您的数据库查询中,首先检查值,如果存在相同的值,则在数据库中停止插入。



希望它可以帮到你。

谢谢。


2. In your db query, first check for value, if same value exist stop inserting in db.

Hope it helps you.
Thanks.


这篇关于为什么页面在刷新时会在数据库中插入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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