Dropdown in ASCX, when to databind?

C

cmay

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.
 
B

bruce barker

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

-- bruce
 
C

cmay

bruce said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top