B
bryanp10
I have a page that is almost entirely dynamically created. Textboxes
and checkbox are working fine, firing events, and persistent their
state. DropDownList is giving me a major headache.
All my controls are created in CreateChildControls() for my custom
control. Here's a snippet of code:
DropDownList dd = new DropDownList();
dd.ID = "DropDown1";
if( !Page.IsPostBack )
{
//dd.DataSource = GetListItems();
//dd.DataBind();
dd.Items.Add( new ListItem("Apples", "1") );
dd.Items.Add( new ListItem("Bananas", "2") );
dd.Items.Add( new ListItem("Oranges", "3") );
int i = dd.Items.IndexOf( new ListItem( user.FruitChoice ));
if( i != -1 ) dd.SelectedIndex = i;
}
dd.SelectedIndexChanged +=new EventHandler(dd_SelectedIndexChanged);
//dd.AutoPostBack = true;
Controls.Add(dd);
The event handler never executes. My list items are not present after
a post-back. How do I persist this and get the data out of it? Why is
my event handler not firing?
I've tried re-creating the list items every time... I've tried the
autopostback obviously... I've tried explicitly assigning a control ID.
Nothing is working.
I've read a *ton* of old newsgroup posts about this very subject over
the last hour or two, but either it's a different problem or no
solution posted.
Anybody have some pointers here?
-Bryan
and checkbox are working fine, firing events, and persistent their
state. DropDownList is giving me a major headache.
All my controls are created in CreateChildControls() for my custom
control. Here's a snippet of code:
DropDownList dd = new DropDownList();
dd.ID = "DropDown1";
if( !Page.IsPostBack )
{
//dd.DataSource = GetListItems();
//dd.DataBind();
dd.Items.Add( new ListItem("Apples", "1") );
dd.Items.Add( new ListItem("Bananas", "2") );
dd.Items.Add( new ListItem("Oranges", "3") );
int i = dd.Items.IndexOf( new ListItem( user.FruitChoice ));
if( i != -1 ) dd.SelectedIndex = i;
}
dd.SelectedIndexChanged +=new EventHandler(dd_SelectedIndexChanged);
//dd.AutoPostBack = true;
Controls.Add(dd);
The event handler never executes. My list items are not present after
a post-back. How do I persist this and get the data out of it? Why is
my event handler not firing?
I've tried re-creating the list items every time... I've tried the
autopostback obviously... I've tried explicitly assigning a control ID.
Nothing is working.
I've read a *ton* of old newsgroup posts about this very subject over
the last hour or two, but either it's a different problem or no
solution posted.
Anybody have some pointers here?
-Bryan