Asp.net 回发 oninit
我有一个带有一个 TemplateField 的网格,它是一个复选框,并有 2 个绑定字段。
在回发时的 Page_Load 中,我使用会话中存储的缓存数据集重新绑定网格。如果用户选择网格上的复选框,则在回发时我可以在网格上迭代并获取这些选中的值,一切正常。
如果我将回发时的网格绑定代码移至 OnInit 而不是 Page_Load,那么我会丢失那些用户选中的复选框数据。为什么? oninit 后回发数据是否不应覆盖在网格顶部?
它确实适用于 page_load,我假设当我重新绑定网格时,我将数据覆盖在具有回发数据的网格上,因为复选框列未绑定,所以我不会覆盖回发数据。
注意:视图状态在我的网格上被禁用,我在每次回发时绑定数据(存储在会话中)。还有一些奇怪的事情,当我使用 OnInit 时,在每次回发时,无论触发哪个页面回发,我都会获得网格的第一页。 谢谢。
I have a grid with one TemplateField which is a checkbox and say 2 bound fields.
In Page_Load on postback I rebind the grid with cached dataset stored in session. If user selects checkbox on the grid, upon postback i can iterate on the grid and get those checked values, everything works fine.
If I move the code of grid binding on postback to OnInit instead of Page_Load then i loose those user checked checkbox data. Why? Should the postback data not overlay on top of the grid after oninit?
It does work with page_load, I'm assuming that when i rebind the grid, I'm overlaying my data on grid which has postback data, since the checkbox column is not bound i do not overwrite postback data.
NOTE: viewstate is disabled on my grid, i bind data (stored in session) on everyback postback. Also something weird, when I'm using OnInit, on every postback i get the first page of the grid, no matter which page the postback was triggered.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信这是因为视图状态尚未在 OnInit 事件中加载。查看http://msdn.microsoft.com/en-us/library /ms178472.aspx 了解有关 asp.net 页面生命周期的更多信息。希望有帮助!!
I believe this is because the viewstate isn't loaded yet in the OnInit event. Check this out http://msdn.microsoft.com/en-us/library/ms178472.aspx for more on the asp.net page lifecycle. Hope it helps!!
与 LoadViewState 类似,ProcessPostData 发生在 OnInit 之后、Page_Load 之前。我假设复选框值作为发布数据运回服务器。因此,我怀疑问题与启用 ViewState 时的问题相同:OnInit 太早 - 发布的数据(复选框值)尚未应用于您的控件。
我在视图状态禁用操作方面没有丰富的经验,因此,如果这个答案缺少一些细微差别,我深表歉意。
Similar to LoadViewState, ProcessPostData is something that happens after OnInit, but before Page_Load. I assume that the checkbox values are shipped back to the server as Post data. Thus I suspect the problem is the same as if ViewState was enabled: OnInit is too early - the posted data (checkbox values) hasn't yet been applied to your controls.
I don't have extensive experience with viewstate-disabled operation, so my apologies if this answer is missing some nuances.
有人在asp.net论坛上回答了这个问题。这是链接
http://forums.asp.net/p/1592192/ 4036031.aspx#4036031
Someone answered it on asp.net forum. Here is the link
http://forums.asp.net/p/1592192/4036031.aspx#4036031