页面刷新时再次触发 GridView_RowCommand 事件

发布于 2024-10-14 15:15:22 字数 230 浏览 4 评论 0 原文

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

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

I have implement GridView Row Editing feature in my .net application using <asp:CommandField.
I clicked on Update button to save the record after editing the row.Now if i refresh the page or press F5 GridView_RowCommand fired again.

How can we avoid this.Is there any mechanism to identify when user press F5 OR refresh the page.Is there any method in client side or in server side.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盛夏已如深秋| 2024-10-21 15:15:22

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

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

戴夫

Not exactly the best "technical" solution to your problem but you could always just do a Response.Redirect(Request.RawUrl) once you have finished doing anything you need to do in your RowCommand

Like I said, it's not the best "technical" solution but it is a solution

Dave

残花月 2024-10-21 15:15:22

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

One method of capturing this is to maintain a session variable that is related to the page in question. In the session variable you would keep some kind of state enumeration, key or string that would determine the last action taken. You could even use a simple incremented counter, and if you ever received a postedback counter that was equal to the session variable it would indicate a page refresh rather than a new action.

如果没有 2024-10-21 15:15:22
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.
    }
}
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.
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文