Wednesday, March 28, 2012

Dynamic Cascading DropDownLists

Hi All,

Thx, for your help in advance. I have 2 update panels, UpdatePanel1 and UpdatePanel2 respectively.

UpdatePanel1 has 'n' dynamically generated DropDownLists with their CascadingDropDown extender.

UpdatePanel2 has a TextBox and a Button.

When the last dynamically generated dropdownlist is clicked (a selectedIndexChanged event is fired) where I clear the TextBox. Since they are dynamically generated, I always add the dynamic dropdownlists (and extenders) on the OnInit event of the page. My problem is that when the Button is clicked, the DropDownLists may be still loading their values (some default selected values, selected via cascadingDropDown.SelectedValue property), so on postback the SelectedIndexChanged event is fired, before the OnClick event of the button takes place. This causes the following scenario:


1. DropDownLists Dynamically Added

2. User Enters Text (DropDownLists StillLoading their default values)

3. User Clicks Button (DropDownLists StillLoading their default values)

4. SelectedIndexChanged Fired (this clears the textbox , so I can't read the value in step 2)

5. Button's OnClick Fired

6. When I try to read the TextBox text, it has been cleared in step 4.

Am I doing something rong? Why both events(SelectedIndexChanged and OnClick) are fired when I'm expecting only the OnClick event to happen. Any thoughts of how to avoid this?


Thx




Hi Maxdmvp,

First, we suggest that you should set your UpdatePanel's UpdateMode="Conditional". This will avoid that one UpdatePanel cause to another UpdatePanel's refreshment.

maxdmvp:

4. SelectedIndexChanged Fired (this clears the textbox , so I can't read the value in step 2)

5. Button's OnClick Fired

You should use a debugging tool such as Web Development Helper and FireBug to find out the reason.

Best regards,

Jonathan


Thx for your response Jonathan...


The problem that I describe rises when you try to edit. Imagine this scenario: The dropDownList's (updatePanel1) are properties of a product, when you finish selecting you have assembled a product model number. When you enter the page to edit how many items of this product you want in your cart (textBox and button in UpdatePanel2), you already know the product's properties (you preselect the values in the dropDownList's), but while these are loading it is posible for you to enter a number in the textBox and click the "add" button in UpdatePanel2. In this scenario the "SelectedIndexChanged" is fired before the "OnClick" of the button, when I just expect the "OnClick" to be fired. As you can see it doesn't matter, in this case, if the UpdateMode="Conditional".

Also thx for your advice on user FireBug, I use it often but I'm not sure how can it help me debug this problem... could you please provide a further advice?

Thx



Hi Maxdmvp,

I'm not clear enough now, so would you please give me a sample now? Please do me a favor that remove all the unnecessary part before you post it. Thanks.

Best regards,

Jonathan.

No comments:

Post a Comment