Wednesday, 3 August 2011

How Does ASP.Net Retain Repeater State?

I'm working on a project which utilises a Repeater control to serve up a set of complicated, dynamic survey questions.
What baffeled me for some time was:
How do i retrieve the answers to the questions on PostBack?
Seems like a pretty amateur question I know...but the problem was my own assumption:
"I should only be binding the Repeater on initial Page Load (ie !IsPostBack || Not IsPostBack) otherwise the answers to the questions will be over-ridden."
However, to my ultimate suprise, this is not the case.
In fact, i the retrieve the set of questions from the Database and bind them to the Repeater on each and every PostBack...(not efficient I know, should probably retrieve from Session on all but initilal PageLoads).
Either way, ASP.Net somehow manages this and doesn't wipe the state of the Repeater clean...the answers are maintained !
I want to know: how does it do this???
The obvious guess is ViewState - but even still, how does it know not to splat the state after i've re-assigned the DataSource and called DataBind()???
What if i actually wanted to Reset the whole thing and actually destroy the state, start from scratch again?
What am i missing here?

No comments:

Post a Comment