Saturday, March 24, 2012

CascadingDropDownList - cant handle more than 765 items!

Hello,

My CascadingDropDownList gives me Method 500 error when more than 765 items are returned from the webservice! Is there a way to fix this? Thanks..

Hi,

that's probably related with the limit for the max size of the JSON payload set by ASP.NET AJAX. You can change it in the web.config:

<jsonSerialization maxJsonLength="500" />


this certainly worked! thank you!
Thanks! Helped me alot.
I have tried putting that in every section and it always errors out as unkown element, if someone can help I would really appreciate it!

Hi,

it must be added inside the configuration -> system.web.extensions -> scripting -> webServices section.


Thank you!

Hi,

I have changed the web config maxJsonLength to 1000. But i dont have that many values. First dropdown is giving me a value but on the second dropdown I am getting method error 500. My webservice code is as follows.

Imports

System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

<WebService(Namespace:=

"http://tempuri.org/")> _
<System.Web.Script.Services.ScriptService()> _

Public

Class MIService
Inherits System.Web.Services.WebService
Shared _DocumentAs XmlDocument
Shared _lockAsNewObject
PublicReadOnlyProperty Document()As XmlDocument
Get
If (_DocumentIsNothing)Then
SyncLock _lock
_Document =New XmlDocument
_Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/MIService.xml"))
EndSyncLock
EndIf
Document = _Document
ExitProperty
EndGet
EndProperty
PublicReadOnlyProperty Hierarchy()AsString()
Get
Dim _HeirarchyAsString() = {"city","zip"}
Return _Heirarchy
EndGet
EndProperty
<WebMethod()> _
PublicFunction GetDropDownContents(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
'Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionaryAsNew StringDictionary
knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
EndFunction
EndClass

My code for aspx file is:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="False"%>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scriptrunat="server">
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
ReturnNew MIService().GetDropDownContents(knownCategoryValues, category)EndFunction
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList3"runat="server"AutoPostBack="True"Width="200px">
</asp:DropDownList><br/>
<br/>
<asp:LabelID="Label1"runat="server"Width="224px"></asp:Label><br/>
<br/>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServiceMethod="GetDropDownContentPageMethod"TargetControlID="DropDownList2"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown3"runat="server"Category="county"LoadingText="[loading County..]"ParentControlID="DropDownList2"PromptText="Please select county."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList3"></cc1:CascadingDropDown>
<br/>
<br/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


Hi,

I have changed the web config maxJsonLength to 1000. But i dont have that many values. First dropdown is giving me a value but on the second dropdown I am getting method error 500. My webservice code is as follows.

Imports

System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

<WebService(Namespace:=

"http://tempuri.org/")> _
<System.Web.Script.Services.ScriptService()> _

Public

Class MIService
Inherits System.Web.Services.WebService
Shared _DocumentAs XmlDocument
Shared _lockAsNewObject
PublicReadOnlyProperty Document()As XmlDocument
Get
If (_DocumentIsNothing)Then
SyncLock _lock
_Document =New XmlDocument
_Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/MIService.xml"))
EndSyncLock
EndIf
Document = _Document
ExitProperty
EndGet
EndProperty
PublicReadOnlyProperty Hierarchy()AsString()
Get
Dim _HeirarchyAsString() = {"city","zip"}
Return _Heirarchy
EndGet
EndProperty
<WebMethod()> _
PublicFunction GetDropDownContents(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
'Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionaryAsNew StringDictionary
knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
EndFunction
EndClass

My code for aspx file is:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="False"%>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scriptrunat="server">
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
ReturnNew MIService().GetDropDownContents(knownCategoryValues, category)EndFunction
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList3"runat="server"AutoPostBack="True"Width="200px">
</asp:DropDownList><br/>
<br/>
<asp:LabelID="Label1"runat="server"Width="224px"></asp:Label><br/>
<br/>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServiceMethod="GetDropDownContentPageMethod"TargetControlID="DropDownList2"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown3"runat="server"Category="county"LoadingText="[loading County..]"ParentControlID="DropDownList2"PromptText="Please select county."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList3"></cc1:CascadingDropDown>
<br/>
<br/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Thank You,

Nepalaya


Hi,

what's the content of the 500? You can useFiddler to examine it.


I hope u get it the way you want, but 765 items in a drop down list isn't very user friendly? Think about screen res?

Maybe test out autocomplete control?

Just giving my view, but if you want 1000 items in a drop down list, go for it :P (I know how annoying it is when people try to divert you from the solution you want, so go for what is best in your app, just throwing out a suggestion)


Hi,

The problem resolved. It was not related with the lenght. Page method was not working so change the service method name to GetDropDownContents and it works.

<

cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1">
</cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServicePath="MIService.asmx"ServiceMethod="GetDropDownContents"TargetControlID="DropDownList2">
</cc1:CascadingDropDown>

Thanks,

Nepalaya


Hello freinds,

I am not able to fill the cascading drop down using database. Does any one have fill it with the database??

Please help me i am stuck with this problem.

Thaks in advance.


Hi,

I get method error 500 in dropdownlist1 . Iam using WEB SERVICE .

i used <jsonSerializationmaxJsonLength="500" /> in web.config but still i get the error.

Can any one help ?

Thanks

No comments:

Post a Comment