If you are creating the items for your dropdownlist imperatively as opposed to declaratively, then make sure you are adding the items early (i.e. before the page load event handler ). The dropdownlist will also maintain it’s items in viewstate, so if you populated it once imperatively, then there is no need to repopulate after a postback, if it’s not necessary for your solution that is.
Ahh your adding an item from the clientside. I was under the impression you were setting an existing item in your dropdownlist as selected from the client and then expecting the SelectedIndexChanged event handler to fire, which is also what I tested ^^
The SelectedIndexChanged handler fires only when an option element ( ListItem) selected attribute/property changes and not when a new option element or ListItem is added, whether clientside or on the server.
There is no pretty builtin way to fix your problem. The best advice is the one from jwmcpeak because your adding new options to the dropdownlist control from the client, so you are changing existing options in a dropdownlist that were rendered from the server. ASP .NET webforms has a builtin EventValidation mechanism where it checks exactly this and treats it as a potential threat. Ofcourse you can disable EventValidation but not recommended as you open up a security hole.
If the new option values you are adding are known values, you can register them for event validation and workaround but it’s still long winded and ends up being a convoluted solution.
Just like to say ale55andro , great answers dude !
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.