Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dropdown in ASCX, when to databind?

Reply
Thread Tools

Dropdown in ASCX, when to databind?

 
 
cmay
Guest
Posts: n/a
 
      12-11-2006
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.

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      12-11-2006
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.
>

 
Reply With Quote
 
 
 
 
cmay
Guest
Posts: n/a
 
      12-12-2006

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1 Gridview. Dropdown A is column from database, Dropdown B is column from database, Data in A and B must be from same row. anonymoushamster@gmail.com ASP .Net 2 11-07-2007 12:40 PM
ajax cascading dropdown: second dropdown disabled acadam ASP .Net 0 12-27-2006 10:59 AM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Select dropdown box bleeds into Javascript dropdown menu Mike HTML 1 12-18-2003 09:49 PM
Edit Mode - How do I populate dropdown in edittemplate from dropdown in another column? Steve Myers ASP .Net Datagrid Control 2 11-20-2003 01:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57