1 Aralık 2011 Perşembe

Repeater disappears on postback

Lately I've been struggling with an ASP.NET Repeater control that holds some other controls in it which dynamically gets loadad with data.
I seemed to have one problem that whenever a postback occurs the repeater was disappearing.As much as I learned from my searches on the internet Repeater control is a dynamic control that needs to be databinded at every postback, I also learned that Page_Load is late for databinding to the repeater and it should be done in Repeater's Init method.
I really don't like these kind of controls but they are very handy in some cases, especially when you need to show dynamic or huge amount of records.In my scenario there were the categories and products at the top of the page you can add new category which is not in repeater but when add button is clicked repeater needs to be refreshed because it holds the categories list, and for deletion this is the same.

After all, I found out that my solution is about the ViewState, the repeater's EnableViewState property was set to false I turned it to true and nothing else was needed.

Here are some links I found benefitial:
Repeaters and Lost Data After Postback (Viewstate)
ViewState and Repeater Control
Repeater DataBinding on PostBack and base.DataBind()