ASP.NET GridView 和 UpdatePanel

发布于 2024-08-26 17:00:06 字数 837 浏览 4 评论 0原文

我有一个 GridView,位于页面上的 UserControl 内、UpdatePanel 内。

GridView 中有一个 Button 需要触发 PostBack。发生的情况是: 用户点击 Button -> RowCommand 触发 ->自定义事件在 UserControl 上引发 -> Page 检测到这一点并更改 MultiView 的活动视图索引以及页面标题和 UpdatePanel 外部的一些其他控件。

问题是,页面异步回发,页面标题发生更改,但需要完整的 PostBack 的操作不会发生,因为完整的 PostBack 不会发生。

要将按钮注册为 PostBack 触发器,我正在使用:

ImageButton btnResults = e.Row.FindControl("btnResults") as ImageButton;
ScriptManager scrCurrent = ScriptManager.GetCurrent(this.Page);
if (btnResults != null && scrCurrent != null) {
    scrCurrent.RegisterPostBackControl(btnResults);
}

我知道这是一个有点复杂的问题,但我真的很感谢任何帮助。

I have a GridView, inside a UserControl, inside an UpdatePanel on a page.

There's a Button in the GridView which needs to fire a PostBack. What happens is:
User clicks Button -> RowCommand Fires -> Custom event is raised on UserControl -> Page detects this and changes the active view index for a MultiView and also the page title and some other controls outside the UpdatePanel.

The problem is, the page posts back asyncchronously, the page title changes, but the actions requiring a full PostBack don't happen because a full PostBack doesn't occur.

To register the button as a PostBack trigger I'm using:

ImageButton btnResults = e.Row.FindControl("btnResults") as ImageButton;
ScriptManager scrCurrent = ScriptManager.GetCurrent(this.Page);
if (btnResults != null && scrCurrent != null) {
    scrCurrent.RegisterPostBackControl(btnResults);
}

I know this is a bit of a complicated problem, but I'd really appreciate any help.

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

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

发布评论

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

评论(1

牵强ㄟ 2024-09-02 17:00:06

最终的解决方案是按原样使用上述代码,但在 RowCreated 事件中而不是在 RowDataBound 中。显然,ASP.NET 的怪癖之一是,有时事件顺序令人惊讶且看似不可预测。出于同样的原因,我总是发现最好尽可能晚地注册 JavaScript,因此我通常使用 SaveStateComplete 事件。

The eventual solution was to use the above code as is, but in the RowCreated event instead of the RowDataBound. Evidently one of the quirks of ASP.NET, sometimes event order is surprising and seemingly unpredictable. For the same reason, I've always found it best to register JavaScript as late as possible, so I usually use the SaveStateComplete event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文