Showing posts with label country. Show all posts
Showing posts with label country. Show all posts

Saturday, March 24, 2012

CascadingDropDown Work only locally

HI,

I basically followed the sample toolkitCascadingdropdown. i only need 2 dropdown lists - Country and State.

everything works find on both local and live server. but when I'm calling the webservice from another website it has problems - a javascript error

<asp:DropDownList ID="ddlCountry" runat="server" />
<asp:DropDownList ID="ddlState" runat="server" />

<ajaxtoolkit:cascadingdropdown id="CascadingDropDown1" runat="server" category="State" loadingtext="Please wait..." parentcontrolid="ddlCountry" prompttext="Select a country"
servicemethod="GetStatByCountryID" servicepath="http://www.domainname.com/WebService/AddressService.asmx" targetcontrolid="ddlState">
</ajaxtoolkit:cascadingdropdown>

all sample I've seen is for working locally - both dropdownlists and webservice are sitting in the same website.

wondering if anyone can show me show to implement this cascadingdropdown by calling an external webservice

much appreciated

Hi,

So your intention is to call a external web service?

XmlHttpRequest object can't access external web service directly for security reasons. So, you may achieve this by adding a web service in the same domain, and this web service calls the external service. On client side, use this new web service to access the external web service indirectly.

Hope this helps.


This is exactly what I did, works out perfectly.

I created a local webserivce calling the external one.

much appreciated for your reply.

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 incompatible with WebServices using GET?

I'm using a trio of cascadingdropdowns representing country/state/city throughout a web application I'm developing for a client. They've recently reduced their internet speed dramatically (from 7mbps to 728k) and suddenly I've had to become more concerned about bandwidth usage.

I'd like to switch my webservice to use GET so that client browsers can cache the results without re-requesting from the server, unfortunately when I try, my select boxes show the error: 12030 (occasionally 12031)

WebService Code:

1<Services.WebMethod(cacheduration:=60), Script.Services.ScriptMethod()> _2Public Function GetCountries(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()3Dim cachedurationAs TimeSpan = TimeSpan.FromMinutes(1)4Dim maxageAs System.Reflection.FieldInfo = HttpContext.Current.Response.Cache.GetType().GetField("_maxAge", Reflection.BindingFlags.InstanceOr Reflection.BindingFlags.NonPublic)5 maxage.SetValue(HttpContext.Current.Response.Cache, cacheduration)6 Context.Response.Cache.SetCacheability(HttpCacheability.Public)7 Context.Response.Cache.SetExpires(Now.Add(cacheduration))8 Context.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate")9Dim cadapterAs New ltcodebehind.DSTablesTableAdapters.countryTableAdapter10Dim ctableAs New ltcodebehind.DSTables.countryDataTable11 cadapter.Fill(ctable)12Dim valuesAs New List(Of CascadingDropDownNameValue)13For iAs Integer = 0To ctable.Count - 114 values.Add(New CascadingDropDownNameValue(ctable(i).Title, ctable(i).ID))15Next1617 Return values.ToArray1819End Function

Client source code

1 <asp:ScriptManager runat="server" ID="acm1" >23 </asp:ScriptManager>4 <ajaxtoolkit:CascadingDropDown runat="server" ID="atlascascmgr" ServicePath="../Services/skService.asmx" SelectedValue="229" Category="country" ServiceMethod="GetCountries" TargetControlID="ddlcountry" />5 Country<br />6 <asp:DropDownList ID="ddlcountry" runat="server" />

Some notes

The only different on whether I receive an error 12030 is whether I have theusehttpget:=Truein the scriptmethod, so my cascadingdropdowns are configured properly for POST operations, I specifically need to know what I can change to get it to accept GET operations.

Usually its around this time that someone might offer up serverside caching, so I'm going to go ahead and answer that question now. 1) I appreciate the goodwill, I'm not being snarky, just trying to preemptively headd of the answer 2) I'm caching the webservice via the cacheduration:=60 up above, it just doesn't help because the server has power to spare, its the clients browsers that need the help.

Thanks everyone for their potential answers. :)

The third parameter to ASP.NET AJAX's Sys.Net.WebServiceProxy.invoke method is called "useGet" and tells it whether to use GET or POST for the web service call. The Toolkit's CascadingDropDownBehavior.js currently hard-codes this parameter to false (meaning "use POST"), so that's likely the source of the problem here. You should be able to change the value to true and rebuild for your client. If that works for you, pleaseopen a work item to ask that we expose this setting as a parameter to CascadingDropDown extender itself so that it will be easy to change for others who might want to do so. Thank you!

Very interesting, I'll do it when I have the time and if it works, open the work item like you describe.

Thanks!