ASP.NET Repeater ItemDataBound happening AFTER PreRender event?
Asked Answered
S

3

10

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?

Updates:

  • The Repeater uses an ObjectDataSource with the DataSourceID declarative set in the repeater control.

  • The DataSource ID or object is not modified at all during the page life-cycle.

Spoonful answered 20/10, 2008 at 18:53 Comment(0)
F
7

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.

Fluorescence answered 20/10, 2008 at 20:32 Comment(3)
If that is true than how do you explain this: msdn.microsoft.com/en-us/library/ms178472.aspx PreRender | Before this event occurs: Each data bound control whose DataSourceID property is set calls its DataBind method.Spoonful
I tested with a simple page. Here is the order in which the events were executed: Page_Load Page_PreRender Repeater1_DataBinding Repeater1_ItemDataBound Repeater1_PreRender According to Reflector the Repeater.EnsureDataBound is called in Repeater.OnPreRender.Fluorescence
You are correct! Thanks! Looks like the repeater is not your average data-bound control!Spoonful
C
1

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.

Chondro answered 20/10, 2008 at 19:55 Comment(1)
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.Spoonful
C
0

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.

Columba answered 20/10, 2008 at 19:16 Comment(1)
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!Spoonful

© 2022 - 2024 — McMap. All rights reserved.