本文介绍了刷新页面,重复的数据库事务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过30 aspx页面,我最近发现了一个问题,如果我做任何喜欢的插入,更新数据库事务,删除,再经过该交易完成我pressed F5或反正刷新页面同样是发生交易

I have over 30 aspx pages, i have discovered a problem recently that if i did any kind of database transaction like insert, update, delete and then after the transaction is complete i pressed F5 or refreshed the page in anyway the same is transaction occur.

我搜索了一个解决办法,但我能发现的是,我必须检查视图状态上的每个按钮,这是不可能的,因为那意味着将有大量的工作。有必须是通用的解决方案,请大家帮我这个问题。

I searched for a solution but all i could found is that i have to check for viewstate on each button which is impossible, cause that means there will be a lot of work. There got to be generic solution, please help me in this problem.

编辑:

下面是关于这在数据库中更改值的一个按钮的code为true或false:

Here is the code on one of the buttons which change a value in data base to either true or false:

 protected void btn_Publish_Click(object sender, EventArgs e)
{

    if (Convert.ToBoolean(int.Parse(hf_Published.Value.ToString())))
    {
        publish(false);
    }
    else
    {
        publish(true);

    }

}

在code执行后,如果刷新执行相同的code中的页面,我注意到,因为一个破发点放在此方法。

After the execution of the code if refreshed the page the same code is executed, i noticed that since a break point was placed on this method.

推荐答案

您可以试试这个。我在几个项目中成功合作用这个。

You can try this. I used this in several project and working successfully.

 public bool IsRefreshed
    {
        get
        {
            if (Convert.ToString(Session["RefreshTimeStamp"]) == Convert.ToString(ViewState["RefreshTimeStamp"]))
            {
                Session["RefreshTimeStamp"] = HttpContext.Current.Server.UrlDecode(System.DateTime.Now.ToString());
                return false;
            }
            else
            {
                return true;
            }
        }
    }




protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        ViewState["RefreshTimeStamp"] = Session["RefreshTimeStamp"];
    }



protected override void OnLoad(EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            Session["RefreshTimeStamp"] = HttpContext.Current.Server.UrlDecode(System.DateTime.Now.ToString());
        }
        base.OnLoad(e);
    }

这篇关于刷新页面,重复的数据库事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:31