Showing posts with label countries. Show all posts
Showing posts with label countries. Show all posts

Wednesday, March 21, 2012

CascadingDropDown problem with the v1.0 version

Hi all,

in one of my pages, i have two dropdowns: one for listing countries and the second for listing the states/provinces of the country selected in the first one dropdown.

When i was using the AJAX Release candidate version, I used the cascadingdropdown without problem. But when i installed the v1.0, the cascadingdropdown stop updating the second dropdown, as used to. Is there someone who can tell me what i am doing wrong?

Part of my code in the aspx file:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel id="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>

<TABLE style="WIDTH: 100%; TEXT-ALIGN: left">
<TBODY> <TR>
<TD style="WIDTH: 328px; TEXT-ALIGN: left">
<asp:DropDownList id="CountryDropDownList" tabIndex=12 runat="server" Width="204px" AutoPostBack="True" DataTextField="Name" DataValueField="Id"></asp:DropDownList>
</TD>

<TD style="WIDTH: 328px; HEIGHT: 24px; TEXT-ALIGN: left">
<asp:DropDownList id="ProvinceDropDownList" tabIndex=12 runat="server" Width="204px" DataTextField="Name" DataValueField="Id"></asp:DropDownList>
</TD>
</TBODY>
</TABLE>

<cc1:CascadingDropDown id="CascadingDropDown1" runat="server" TargetControlID="CountryDropDownList" Category="Country" ServicePath="CustomerSignUp.aspx" ServiceMethod="GetAllCountries" PromptText="<%$ Resources:Messages, SelectCountry %>" LoadingText="<%$ Resources:Messages, Loading %>"></cc1:CascadingDropDown>

<cc1:CascadingDropDown id="CascadingDropDown2" runat="server" TargetControlID="ProvinceDropDownList" Category="Province" ServicePath="CustomerSignUp.aspx" ServiceMethod="GetCountryProvinces" PromptText="<%$ Resources:Messages, SelectProvince %>" LoadingText="<%$ Resources:Messages, Loading %>" ParentControlID="CountryDropDownList"></cc1:CascadingDropDown>

</ContentTemplate>
</asp:UpdatePanel>

</asp:Content>

Methods in the aspx.cs file:

[WebMethod]
public static CascadingDropDownNameValue[] GetAllCountries(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
ICollection<Country> countries = KinocastFacade.Instance.GetAllCountries();
foreach (Country country in countries)
{
values.Add(new CascadingDropDownNameValue(
Resources.Messages.ResourceManager.GetString(country.Name), country.Id.ToString()));
}

return values.ToArray();

}

[WebMethod]
public static CascadingDropDownNameValue[] GetCountryProvinces(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(
knownCategoryValues);
int countryId;

/*Verifica se a chave country está no StringDictionary e se é possivel
*fazer o parse do seu valor para inteiro. Se possivel coloca o valor
*em countryId*/
if (!kv.ContainsKey("Country") ||
!Int32.TryParse(kv["Country"], out countryId))
{
return null;
}

List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
ICollection<Province> provinces = KinocastFacade.Instance.GetCountryProvinces(countryId);
foreach (Province province in provinces)
{
values.Add(new CascadingDropDownNameValue(
Resources.Messages.ResourceManager.GetString(province.Name), province.Id.ToString()));
}

return values.ToArray();
}

Thanks a lot for any help,

Rodrigo

Anyway,

I've just resolved my problem re-creating the project, including all my files and modules again. And at the end, i include the AjaxControlToolkit.dll (version 1.0.10301.0) and the cascadingdropdown problem disapeared.

Maybe, it had happened because the VS saves some olds DLLs in a limbo place :p ...... I dont know...

Cheers.


CascadingDropDown Method error 500

Hi,

I have a problem with cascading drop down. I tried to reproduce the video tutorial with countries and states instead of cars. I can manage to get the first one to work but the second one give me the [Method error 500]. I don't know where I made a mistake.

I really hope someone can answer me.

FMaheu

************** Web service CountryService.asmx *****Imports System.WebImports System.Web.ServicesImports System.Web.Services.ProtocolsImports System.Xml<WebService(Namespace:="http://tempuri.org/")> _<System.Web.Script.Services.ScriptService()> _Public Class CountryServiceInherits System.Web.Services.WebServiceShared _DocumentAs XmlDocumentShared _lockAs New Object Public ReadOnly Property Document()As XmlDocumentGet If (_DocumentIs Nothing)Then SyncLock _lock _Document =New XmlDocument _Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/Copy of countries.xml"))End SyncLock End If Document = _DocumentExit Property End Get End Property Public ReadOnly Property Hierarchy()As String()Get Dim _HierarchyAs String() = {"country","state"}Return _HierarchyEnd Get End Property <WebMethod()> _Public Function GetDropDownContents(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As AjaxControlToolkit.CascadingDropDownNameValue()Dim knownCategoryValuesDictionaryAs New StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)End FunctionEnd Class************************ aspx file ********<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title> <script runat="server"> <System.Web.Services.WebMethod()> _ <System.Web.Script.Services.ScriptMethod()> _Public Shared Function GetDropDownContentsPageMethod(ByVal knowCategoryValuesAs String,ByVal categoryAs String)As AjaxControlToolkit.CascadingDropDownNameValue()Return New CountryService().GetDropDownContents(knowCategoryValues, category)End Function </script></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" Width="213px"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" Width="212px"> </asp:DropDownList> <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="country" LoadingText="[Loading countries ...]" ServiceMethod="GetDropDownContents" ServicePath="CountryService.asmx" PromptText="Please select a country" TargetControlID="DropDownList1"> </cc1:CascadingDropDown> <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" ParentControlID="DropDownList1" Category="state" LoadingText="[Loading states ...]" ServiceMethod="GetDropDownContentsPageMethod" PromptText="Please select a state" TargetControlID="DropDownList2"> </cc1:CascadingDropDown> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Nevermind I kinda got it to work somehow ...Confused

Hi FMaheu,

I am having same problem as you mentioned. First dropdown works but second dropdown is giving me error "Method Error 500". Would you please let me know what change that you made on your code to fix that error.

Thank You,

Nepalaya


Hi nepalaya,

Sorry for the delay, I'm very busy these days. So instead of using a page method I used the method in my countryservice.asmx. Something seemed to be wrong with my page method and since I could just use the same method as the first cascading drop down ...

I have also read in other threads that the control could only support a limited number of objects. That could be modified in the web.config file.

I hope this helps

FMaheu

P.S. I posted my ASP.NET Code in case in would help you understand better.

1 <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="country" LoadingText="[Chargement des pays ...]"2 ServiceMethod="GetDropDownContents" ServicePath="CountryService.asmx" PromptText="Sélectionner un pays" TargetControlID="DropDownList1">3 </cc1:CascadingDropDown>4 <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" ParentControlID="DropDownList1" Category="state" LoadingText="[Chargement des états/porvinces ...]"5 ServiceMethod="GetDropDownContents" PromptText="Sélectionner un état/province" TargetControlID="DropDownList2" ServicePath="CountryService.asmx">6 </cc1:CascadingDropDown>7

Thank You very much.

Yes it works.

Thanks,

Mani


I have my code identical to yours and I am getting a method error 12030. Any ideas?

From my search, that error is given to you when your aspx page cannot reach the web service. Is your service external to your web project? If so try copy it inside your web project. It seems calling an external web service doesn't work very well with CascadingDropDown.

Hope this helps a little


my web service (.asmx file) is in my web project. It is weird, sometimes I get method error 500 errors and sometimes I get method error 12030 errors. There isn't a pattern that I can find.
Most likely the web service isn't defined or hooked up properly. The ASP.NET AJAX infrastructure is pretty unforgiving here, so make sure everything is as it should be.