views:

6881

answers:

5

I have a repeater control on an ASP.NET 2.0 web form.

As I understanding it, all of the page's data-bound controls fire their binding events somewhere in between the Page_Load and the Page_PreRender events.

However, my repeater's ItemDataBound event appears to be happening AFTER the PreRender event.

How is this so and is there any way I can access the page controls AFTER all the ItemDataBound events have fired?

Thanks in advance for any light shed.

Updates:

-The Repeater uses an ObjectDataSource with the DataSourceID declaritively set in the repeater control.

-The DataSource ID or object is not modified at all during the page lifecycle.

A: 

I think I had a similar situation, and my option was to FORCE the controls to bind themselves, by calling EnsureChildControls or some similar method.

hova
I know I can force it to databind during Page_Load, but I was just curious as to WHY it was waiting until after the Page_PreRender to bind. Wierd!
Matias Nino
A: 

Are you specifically binding your repeater (myRepeater.DataBind();) in your code behind file (for example inside the Page_Load() event)?

Have you checked out the ASP.NET events lifecycle? Sorry if you already know this, but just in case: http://msdn.microsoft.com/en-us/library/ms178472.aspx

Hope it helps.

Ricardo.

Ricardo Villamil
Nope. The repeater's databind is not explicitly called. That's why I figured it would occur after the page Load but before the PreRender, as stated by the page lifecycle.
Matias Nino
+5  A: 

Declarative databinding (datasource specified via the DataSourceID property) occurs later than the PreRender event. The behavior you are observing is by design. If this is not what you need you should explicitly databind your control - just call its DataBind method.

korchev
If that is true than how do you explain this: http://msdn.microsoft.com/en-us/library/ms178472.aspxPreRender | Before this event occurs:Each data bound control whose DataSourceID property is set calls its DataBind method.
Matias Nino
I tested with a simple page. Here is the order in which the events were executed:Page_LoadPage_PreRenderRepeater1_DataBindingRepeater1_ItemDataBoundRepeater1_PreRenderAccording to Reflector the Repeater.EnsureDataBound is called in Repeater.OnPreRender.
korchev
You are correct! Thanks! Looks like the repeater is not your average data-bound control!
Matias Nino
A: 

There is also a good post about repeater event in the following blog post :

LinkButton ,Label inside Repeater - ASP.NET

A: 

This happens when I click on a linkbutton I created in the detailsview control

Ron Chong