Coder World

November 11, 2007

Ajax cascading dropdown control

Filed under: Ajax — Tags: , , , , — fookean @ 7:26 am

Cascading drop down control is Ajax extension control that extends the functionality of drop down box by filtering items based on the selection on precedent drop down box. There is a very good video tutorial by www.asp.net using web service to retrieve XML documents. After trial and errors, i noticed there are few things need to take note.

1. The root node must be the name of the XML file.

2. EnableEventValidation=false must be set to avoid postback error while clicking on other controls on the form.

3. This statement must be declared prior of declaration of the web service class to avoid method500 error.

[System.Web.Script.Services.ScriptService()]

4. You can still bind the drop down box to certain data member such as this SelectedValue=’‘ so that you can insert/update record through objectdatasource using form parameter.

5. You can always have page level web service such as below for performance purpose. This page level web service must not be in master page, else it does nothing. When using page level web service/function, you don’t have to specific the service path. You only need the specific the method name.

   1:      ///     2:      /// KnownCategory filled up automatically when you select an item and the   sample value     3:      /// as state:California, category is the state.    4:      ///     5:      ///     6:      ///     7:      ///     8:      [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]    9:      public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)   10:      {   11:          return new RegionService().GetRegionContents(knownCategoryValues, category);   12:      }

Blog at WordPress.com.