Saturday, March 24, 2012

CascadingDropDown with a Database, Method Error 405

Hey guys,


I followed the AjaxControlToolki tinstructions on how to create a WebService and specify everything so that it would populate two DropDownLists. The problem is, the first DropDownList has a [Method Error 405] as its only value. If I select it, the second DropDownList is populated with the same.

After checking, rechecking and extensively searching, I haven't found my error. I've read at least a dozen topics on this error but none have helped me.

Here is my code:

App_Code/StateServices.cs:

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Data;

/// <summary>
/// Summary description for StateServices
/// </summary>[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.Web.Script.Services.ScriptService]public class StateServices : System.Web.Services.WebService { GeographicalDelimitationsDB GeoDataSource = new GeographicalDelimitationsDB(); GeographicalDelimitationsDBTableAdapters.CountyInfoTableAdapter GeoCountyInfoTableAdapter = new GeographicalDelimitationsDBTableAdapters.CountyInfoTableAdapter(); GeographicalDelimitationsDBTableAdapters.ZipCodesTableAdapter GeoZipCodesTableAdapter = new GeographicalDelimitationsDBTableAdapters.ZipCodesTableAdapter(); public StateServices() { } [WebMethod] public CascadingDropDownNameValue[] GetCounties(string knownCategoryValues, string category) { GeographicalDelimitationsDB.CountyInfoDataTable counties = GeoCountyInfoTableAdapter.GetData(); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (DataRow dr in counties.Rows) { string name = (string)dr["Name"];
int countyID = (int)dr["CountyCode"];

values.Add(new CascadingDropDownNameValue(name, countyID.ToString()));
}

return values.ToArray();
}

[WebMethod]
public CascadingDropDownNameValue[] GetCitiesForCounty(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int countyID;

if (!kv.ContainsKey("County") || !Int32.TryParse(kv["County"], out countyID))
{
return null;
}

GeographicalDelimitationsDB.ZipCodesDataTable cities = GeoZipCodesTableAdapter.GetDataByCountyID(countyID);

List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

foreach (DataRow dr in cities.Rows)
{
values.Add(new CascadingDropDownNameValue((string)dr["City"], dr["ZIP"].ToString()));
}

return values.ToArray();
}
}

 
index.aspx: 

 <asp:UpdatePanel ID="NavigationUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="ConfigurationContentPart" runat="server" CssClass="module-content">
<h3>County:</h3>
<p>
<asp:DropDownList ID="CountyList" runat="server" onchange="selectCounty(this)" />
</p>
<h3>City:</h3>
<p>
<asp:DropDownList ID="CityList" runat="server" onchange="selectCity(this)" />
</p>
</asp:Panel
<ajaxToolkit:CascadingDropDown ID="CountyCascadingDropDown" runat="server" TargetControlID="CountyList" Category="County" PromptText="Select a County" LoadingText="[Loading...]" ServicePath="StateServices.asmx" ServiceMethod="GetCounties" />
<ajaxToolkit:CascadingDropDown ID="CityCascadingDropDown" runat="server" TargetControlID="CityList" Category="City" PromptText="Select a City" LoadingText="[Loading...]" ServicePath="StateServices.asmx" ServiceMethod="GetCitiesForCounty" ParentControlID="CountyList" /
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>

Bump...

Please help, I'm really stuck!


Does it work without the onchange handlers on the DropDownLists?

No comments:

Post a Comment