ASP.NET GridView 和 UpdatePanel
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终的解决方案是按原样使用上述代码,但在 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.