473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2098
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to...
4
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to...
8
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: CSharpguy | last post by:
I'm trying to populate a drop down with dates from a data field in my data base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM How can I my date to show as 1/1/2006? I'm...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
4
by: | last post by:
I'm building some user controls. I very much like how you can build custom properties to be bound to a user control, and how instances of that control will show those custom properties in the...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
3
by: John | last post by:
I have two dropdown lists that I have bound to a datatable and set the DataTextField and DataValueField for. Both lists show the values I expect from the database. However, when I need to access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.