473,657 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
CreateControlHe irarchy(bool useDataSource) method.

Somewhere between the CreateControlHe irarchy 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 CreateControlHe irarchy(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.Enable ViewState = false;

ddlParent.Attri butes.Add("onch ange",
"UpdateChild(th is.options[this.selectedIn dex].value,'parent' );");
if (useDataSource)
{
//bind datasource to Parent - maintained by viewstate
ddlParent.DataS ource = ParentDataSourc e;
ddlParent.DataT extField = ParentDataTextF ield;
ddlParent.DataV alueField = ParentDataValue Field;

if (objParentList != null)
ddlParent.DataB ind();
}

//always reload & bind child, viewstate is disabled
if (ChildDataSourc e != null)
{
ddlChild.DataSo urce = ChildDataSource ;
ddlChild.DataTe xtField = ChildDataTextFi eld;
ddlChild.DataVa lueField = ChildDataValueF ield;
ddlChild.DataBi nd();

}

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

if (hasAllItem)
{
ddlChild.Items. Insert(0, new
ListItem(AllChi ldItemText,AllC hildItemValue)) ;
}

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

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

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

Controls.Add(lb lParent);
Controls.Add(dd lParent);
Controls.Add(ne w LiteralControl( "<br>"));
Controls.Add(lb lChild);
Controls.Add(dd lChild);

RegisterClientS ideScripts();
}

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

EnsureChildCont rols();
base.Render(wri ter);
}

protected override void CreateChildCont rols()
{
//This event doesn't fire on first page load
Controls.Clear( );
CreateControlHe irarchy(false);

}

protected override void OnDataBinding(E ventArgs e)
{
base.OnDataBind ing(e);

Controls.Clear( );
CreateControlHe irarchy(true);
if (HasChildViewSt ate)
{
ClearChildViewS tate();
}
ChildControlsCr eated = true;
if (!IsTrackingVie wState)
{
TrackViewState( );
}

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

}

Nov 19 '05 #1
0 1584

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

Similar topics

0
1276
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 the DataBinder.Eval method. I can write that value out to the screen, however, it is not available to the control. I think it is a problem with the databinding of the repeater making data available to the custom control too late. Below is a...
2
1542
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 Value. This is what I did till now and I do not know how to pass back the selected value .. Please help public class DDControl : System.Web.UI.WebControls.WebControl, IPostBackEventHandler { protected override void Render(HtmlTextWriter...
7
3338
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, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
5
5961
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 event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add later, right now I am just concerned about the variables getting reset): Public Class DatePicker2...
2
1691
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 textboxes and the dropdownlist) and lots more stuff on the page. When the user wants to save the page he'll click the save button. The server gets the postback but I can read out the filled in controls (in my control). The textboxes text = ""...
0
1323
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 structure. The template items describe how each particular note type of the tree should be rendered (the nodes are data capture elements - bool string and more complicated things). I don't want to use ViewState because of size (there are...
3
2488
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 = DataReader(sSQLcmd) Me.DropDownList1.DataSource = dr
0
1572
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 code looks like this: public class ColumnSelector : Panel {
3
3828
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 DropDownList1 using the ScriptManager SetFocus method. Use the Visual Studio debugger. Set a breakpoint on in the (!IsPostBack) part of the PageLoad method. Start the web application and continue after the breakpoint has been reached.
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.