473,382 Members | 1,204 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,382 software developers and data experts.

Custom Control - DropDownList losing Items

I am building a custom composite control consisting of two drop downs,
with parent/child dependancy.

The child dropdownlist is updated through client callback when the
parent index changes.

An 'All' list item is added to the child dropdown during the
CreateControlHeirarchy(bool useDataSource) method.

Somewhere between the CreateControlHeirarchy method executing and the
Render event the added ListItem disappears. This only happens on the
first page load. Refreshing the browser or doing a postback, everything
works fine.

I put breakpoints all over the code, nothing that touches ddlChild is
executing between the OnDataBinding & Render events.

I must be missing something.

Anyone have any ideas?

Thx.

Here is the relevant sections of the code

protected void CreateControlHeirarchy(bool useDataSource)
{
ddl1 = new DropDownList();
ddlChild = new DropDownList();

ddlParent.ID = this.UniqueID + "parent";
ddlChild.ID = this.UniqueID + "child";

//viewstate gets out of sync on child due to callbacks, so
don't use it
ddlChild.EnableViewState = false;

ddlParent.Attributes.Add("onchange",
"UpdateChild(this.options[this.selectedIndex].value,'parent');");
if (useDataSource)
{
//bind datasource to Parent - maintained by viewstate
ddlParent.DataSource = ParentDataSource;
ddlParent.DataTextField = ParentDataTextField;
ddlParent.DataValueField = ParentDataValueField;

if (objParentList != null)
ddlParent.DataBind();
}

//always reload & bind child, viewstate is disabled
if (ChildDataSource != null)
{
ddlChild.DataSource = ChildDataSource;
ddlChild.DataTextField = ChildDataTextField;
ddlChild.DataValueField = ChildDataValueField;
ddlChild.DataBind();

}

//**** ListItem added here - stepping through code in debug shows
the ListItem has been added ****

if (hasAllItem)
{
ddlChild.Items.Insert(0, new
ListItem(AllChildItemText,AllChildItemValue));
}

Label lblParent = new Label();
lblParent.Text = ParentTitle;
lblParent.EnableViewState = false;
lblParent.Width = labelWidth;

Label lblChild = new Label();
lblChild.Text = ChildTitle;
lblChild.EnableViewState = false;
lblChild.Width = labelWidth;

ddlParent.Width = dropDownWidth;
ddlChild.Width = dropDownWidth;

Controls.Add(lblParent);
Controls.Add(ddlParent);
Controls.Add(new LiteralControl("<br>"));
Controls.Add(lblChild);
Controls.Add(ddlChild);

RegisterClientSideScripts();
}

protected override void Render(HtmlTextWriter writer)
{
//******* Watch on ddlChild.Items shows added ListItem has
disappeared ********

EnsureChildControls();
base.Render(writer);
}

protected override void CreateChildControls()
{
//This event doesn't fire on first page load
Controls.Clear();
CreateControlHeirarchy(false);

}

protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);

Controls.Clear();
CreateControlHeirarchy(true);
if (HasChildViewState)
{
ClearChildViewState();
}
ChildControlsCreated = true;
if (!IsTrackingViewState)
{
TrackViewState();
}

//******* Watch on ddlChild.Items shows added ListItem is still here
when this event exits********

}

Nov 19 '05 #1
0 1576

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joe | last post by:
I am having a hard time with setting a property on a custom server control that i am placing in a repeater. The control inherits from DropDownList. The property is being set in the repeater using...
2
by: Steven | last post by:
This one should be a fairly simple one for you guys. I want to create a small dropDown list (custom control) and when the user selects anyone of the value, the control should pass back the Selected...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
2
by: Pipo | last post by:
Nobody knows how to get the values provided in the client can be read in the user-control? If have made a Web Custom Control with 2 textboxes and 1 dropdownlist. The user fills in my control (the...
0
by: Iain | last post by:
Can I apologise for the lengthy nature of this post. The scenario is complicated (though I hope the solution is not!) basically, I've got a custom template control which binds itself to a tree...
3
by: Carlos Lozano | last post by:
Hello, I am having a problem getting the selectedValue from a dropdownlist that is populated with a dataReader and just can't see the problem. I did the following: dim dr as DataReader dr...
0
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The...
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged method, refill DropDownList2 and set the focus to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.