471,595 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Dropdown in ASCX, when to databind?

A common situation I come across is an ASCX control that being used as
a lookup control.

The ascx might be called "StatusLookup" or something, and it consists
of 1 dropdown list that populates itself from cache/database list.

If you databind on the Init event, then you are databinding every time,
and not making any use of the viewstate.

If you databind on the Load event, you can see if the control has
already been loaded by the viewstate, but if you have code in your
pages Load event, that can run before the Load event on your ASCX
control is fired.

So, you can end up with a situation where you PAGE load method is
trying to set the value of the dropdown in the ASCX, but the ASCX has
not yet databound.

I have always written some code to work around this situation, using a
series of checks to see if items have been added to the dropdown or
not, but I am wondering if there is a better pattern to be followed
when doing something like this.

Dec 11 '06 #1
2 2037
if you turn off viewstate (like I do to save bandidth and make paes
faster) you databind in oninit and its simple.

-- bruce

cmay wrote:
A common situation I come across is an ASCX control that being used as
a lookup control.

The ascx might be called "StatusLookup" or something, and it consists
of 1 dropdown list that populates itself from cache/database list.

If you databind on the Init event, then you are databinding every time,
and not making any use of the viewstate.

If you databind on the Load event, you can see if the control has
already been loaded by the viewstate, but if you have code in your
pages Load event, that can run before the Load event on your ASCX
control is fired.

So, you can end up with a situation where you PAGE load method is
trying to set the value of the dropdown in the ASCX, but the ASCX has
not yet databound.

I have always written some code to work around this situation, using a
series of checks to see if items have been added to the dropdown or
not, but I am wondering if there is a better pattern to be followed
when doing something like this.
Dec 11 '06 #2

bruce barker wrote:
if you turn off viewstate (like I do to save bandidth and make paes
faster) you databind in oninit and its simple.

-- bruce

Are you talking about turning off viewstate at the control, or for the
whole page?

If you have the viewstate totally off, that would cause you to have to
set the selected value of the control every postback.

Dec 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Kris Rockwell | last post: by
2 posts views Thread by Mike Collins | last post: by
3 posts views Thread by CSharpguy | last post: by
5 posts views Thread by jung_h_park | last post: by
3 posts views Thread by John | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.