Showing posts with label dropdowns. Show all posts
Showing posts with label dropdowns. Show all posts

Saturday, March 24, 2012

Dropdowns inside updatepanel flash on postback.

I have 2 dropdown controls inside an updatepanel. One is disabled or enabled dependent on the selection of the other dropdown. The disabled one has its autopostback property set to false. The other one has autopostback=true. When I make selection in dropdown 1, both dropdowns flash. Is there a way to prevent the redrawing of the controls and just have the data in them update?

Thanks,

John

Put the both the DropDownlist control in to its own UpdatePanel.And make the second updatepanel Updatemode ="Conditional" and when you want to second DDL to be enable do it in the code and call the update() method in the UpdatePanel two ..

refer the following link for more information

http://asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx

Wednesday, March 21, 2012

DropdownList controls inside AccordionPane and Clearing ViewState on Control

I'm having problems with ViewState loading stale data on DropDowns embedded within an AccordionPane.

The dropdowns are bound to a generic collection object using Databinding via a 'PopulateList' method that's in a helper class:

//bind a listControl with an objectpublic static void PopulateList(System.Web.UI.WebControls.ListControl list,string valueDataName,string textDataName, Object bindingObject){ list.DataSource = bindingObject; list.DataValueField = valueDataName; list.DataTextField = textDataName; list.DataBind();}
the 'PopulateList' method gets called in the set property of each generic collection object: 

public System.Collections.Generic.IList<GenericCollectionItem<int,string>> PlanList

{get {return _planList; }set { _planList =value; ddPlan.Items.Clear();if (_planList.Count > 0) { ddPlan.Enabled =true; ListHelper.PopulateList(ddPlan,"ID","Description", _planList); }else { ddPlan.Enabled =false; } }}
The problem I'm having is when the list is empty, the dropdown retains the old values even
though the code to clear and disable the dropdown is being executed. Anyone know a way to
clear ViewState for an individual control or have any suggestions on what might be going on?
I don't want to disable the ViewState for the entire page or for the control, because the control
values will only be changed when the generic collection is changed, so i need viewstate for all other times...
Any help greatly appreciated!
Thanks

Hi kylen,

You could try Viewstate.Remove(key)

I think that the key is the ID of the control which viewstate is tracking. (more about viewstate here:http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx )

Another thing you could do is clear the items of the DDL in the load event. The Load occurs after the ViewState has set the last state-values to the controls (Well, I think the load is after ... otherwise try the PreRender of the page)

Let me know if anything worked out!

Kind regards,
Wim