4

我已经使用 .net 应用程序在我的 .net 应用程序中实现了 GridView 行编辑功能<asp:CommandField。编辑行后,我单击更新按钮保存记录。现在,如果我刷新页面或按 F5 GridView_RowCommand 再次触发。

我们如何避免这种情况。是否有任何机制可以识别用户何时按下 F5 或刷新页面。客户端或服务器端是否有任何方法。

4

3 回答 3

5

不完全是解决您的问题的最佳“技术”解决方案,但是Response.Redirect(Request.RawUrl)一旦您完成了 RowCommand 中需要做的任何事情,您就可以随时执行

就像我说的,这不是最好的“技术”解决方案,但它是一个解决方案

戴夫

于 2011-02-09T12:42:53.813 回答
1
Session["LastInsertedItem"] = null;
MyCustomObjType myCustomObject;
protected void Page_Load(object sender, EventArgs e)
{
    myCustomObject = Session["LastInsertedItem"] as MyCustomObjType;
}
void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    If(myCustomObject == null || //!(compare your value with myCustomObject.field) )
    {
         // do your operations and save the values to myCustomObject and save that object back to Session.
    }
    else
    {
        // It is refreshed or same data is being insterted - don't know if second         option is possible in your case.
    }
}
于 2011-01-28T12:18:10.220 回答
1

捕获此问题的一种方法是维护与相关页面相关的会话变量。在会话变量中,您将保留某种状态枚举、键或字符串,它们将确定最后采取的行动。您甚至可以使用一个简单的递增计数器,如果您曾经收到一个等于会话变量的回发计数器,它将指示页面刷新而不是新操作。

于 2011-01-28T12:30:21.820 回答