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 5 4365
Just out of curiosity, I note that you have the AutoPostBack line
commented out. Did you try to set the AutoPostBack to true manually
and this still happens? By default, DDLs are AutoPostBack=false.
Have you tried to debug this to see where the events are actually
going?
Just a thought,
Geek Rex
On 10 Mar 2005 15:18:27 -0800, "br******@hotmail.com"
<br******@hotmail.com> wrote: 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
Yes, I have tried with AutoPastBack. Have you tried to debug this to see where the events are actually
going?
I'm not sure what you mean by this?
Actually, it's just the SelectedIndexChanged event that is not firing.
The Load and Unload events are firing just fine. Which makes it all
the more frustrating...
Where are you building the list? Dynamically built lists need to be built
during the Init event, otherwise event will not fire.
<br******@hotmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com... Yes, I have tried with AutoPastBack.
Have you tried to debug this to see where the events are actually going?
I'm not sure what you mean by this?
Actually, it's just the SelectedIndexChanged event that is not firing. The Load and Unload events are firing just fine. Which makes it all the more frustrating...
I am creating the DropDownList in CreateChildControls. That certainly
seemed like the logical place to do it, given the method name. It's
where I'm creating everything else and those controls are working just
fine.
OK, I just tried building in the OnInit event and sure enough the
SelectedIndexChanged event fired correctly this time. Thanks for the
info Peter. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DotNetJunky |
last post by:
I have built a control that runs an on-line help system. Depending on the
category you selected via dropdownlist, it goes out and gets the child
subcategories, and if there are any, adds a new...
|
by: Donald Xie |
last post by:
Hi,
I noticed an interesting effect when working with controls that are
dynamically loaded. For instance, on a web form with a PlaceHolder control
named ImageHolder, I dynamically add an image...
|
by: Earl Teigrob |
last post by:
PROBLEM:
When a user control is loaded into a PlaceHolder control more than once, the
events do not fire on the first click of a control on the dynamically loaded
user control. In other words, the...
|
by: JoakimR |
last post by:
Hello,
I have a problem with events not firing. I've created a web user
control which renders a calendar using a table control. In two cells
I'm adding LinkButtons for "prev/next month". However,...
|
by: Mark Rae |
last post by:
Hi,
I'm sure I've done this before, but I can't get it to work today...
I'm trying to add a DropDownList into a TableCell and wire up its
SelectedIndexChanged event. I'm adding the dynamic...
|
by: Chad Smith |
last post by:
Hi.
I have an asp.net web application written in C# which creates a datasource
consisting of a Name and a list of permissable Values. This datasource is
then bound to a simple repeater, the Name...
|
by: Dotnet Gruven |
last post by:
I've built a WebForm with a Table added dynamically in Page_Load when
IsPostBack is false. The table includes a couple of TextBoxes,
RadioButtonLists and CheckboxLists.
On postback, those...
|
by: Steve Moreno |
last post by:
Hi all,
I've got a web form that I've written code to create an array of
DropDownList controls on the page depending on how many records are pulled
back. The code to create the controls is...
|
by: Amoril |
last post by:
I've read quite a few different message on various boards and for some
reason I'm still having trouble wrapping my head around this viewstate
maintenance and trying to get these dynamically created...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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: 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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |