468,136 Members | 1,407 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

The problem with DataBind

Say you are creating a page which contains a child control which uses a
DataList or DataGrid control. In a DataList, the rows are dynamic
controls and are data bound, so you have to first load the data source
and then DataBind. The problem arises when the containing Page calls
DataBind before your child control, say in their Page_Load. So you
have a Page with Page_Load calling DataBind and a child control with a
Page_Load and a DataBind.

What happens, I have found, is that on a PostBack, the DataBind is
broadcasted to your child control just after the ViewState is loaded
but before we get to start the child control's Page_Load. Thus, the
DataBind causes the child control to disappear because we bound before
we got to execute the event handler for the PostBack.

Does this make sense? I have solved this problem by overriding
DataBind, but it made me think. Can't all child controls be messed-up
by this problem of a DataBind in a parent control or page? As such,
should all controls override DataBind?

Thanks for your thoughts!
NL

Dec 29 '06 #1
0 896

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by autofill | last post: by
5 posts views Thread by Joel Reinford | last post: by
reply views Thread by Vaidas Gudas | last post: by
2 posts views Thread by Roy | last post: by
reply views Thread by Eric Liprandi | last post: by
reply views Thread by Mike Collins | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.