Asp.net postback 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.
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!!
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.
Someone answered it on asp.net forum. Here is the link
http://forums.asp.net/p/1592192/4036031.aspx#4036031
精彩评论