Dynamic Control loading at wrong time?

Posted by Telos on Stack Overflow See other posts from Stack Overflow or by Telos
Published on 2009-06-12T16:47:59Z Indexed on 2010/04/09 3:03 UTC
Read the original article Hit count: 282

This one is a little... odd. Basically I have a form I'm building using ASP.NET Dynamic Data, which is going to utilize several custom field templates.

I've just added another field to the FormView, with it's own custom template, and the form is loading that control twice for no apparent reason. Worse yet, the first time it loads the template, the Row is not ready yet and I get the error message:

{"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."}

I'm accessing the Row variable in a LinqDataSource OnSelected event in order to get the child object...

Now for the wierd part: If I reorder the fields a little, the one causing the problem no longer gets loaded twice.

Any thoughts?

EDIT: I've noticed that Page_Load gets called on the first load (when Row throws an exception if you try to use it) but does NOT get called the second time around. If that helps any...

Right now managing it by just catching and ignoring the exception, but still a little worried that things will break if I don't find the real cause.

EDIT 2: I've traced the problem to using FindControl recursively to find other controls on the page. Apparently FindControl can cause the page lifecycle events (at least up to page_load) to fire... and this occurs before that page "should" be loading so it's dynamic data "stuff" isn't ready yet.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-dynamic-data