Wednesday, March 21, 2012

CascadingDropDown Method error 500

I have a couple of CascadingDropDown controls on an ASP.NET page and am filling them from a code behind function that makes a call to a SQL Server 2005 database. My problem is that sometimes I receive a 'Method error 500' when filling the second dropdownlist based on a parent control. I am concatenating three fields together and I can mix and match 2 of them, but when I use all three, I consistently get the error.

Example "Select StoreCode + ' ' + City + ' ' State as Name From Table".

Is there a data size limit with using this control?

Also, I am able to bind the same data to a dropdownlist not used in AJAX.

Thanks in Advanced,

Marc


I am encountering a similar problem with some CascadingDropDowns that help define someone's location. Whn I gt tothe City level, sometimes I get a 'Method Error 500' and sometimes I do not.

Your question "Is there a data size limit with using this control?" got me experimenting, and my results suggested that indeed there was a correlation between the error and the amount of data being returned.

So I installed IEInspector and fond that indeed, requests that return a lot of data are creating a problem. This is one of the responses I am getting:

{"Message":"Maximum length exceeded.","StackTrace":" at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
 
My next step is to use Reflctr to look at the code for System.Web.Script.Services.RestHandler.InvokeMethod and see what I discover.
 
Thanks for the data length suggestion!
 

Ken, thanks for the investigative work. Can you please keep me updated as to what you find?

I too will continue to debug this issue and will report any findings to this thread.

Thanks in advance,

Marc


Eureka!

Stepping thru the AJAX source code was tiring but informative.

In any event, here is my solution (if your underlying issue is different, YMMV).

I was hitting a size limit in the JSON conversion stuff, which fortunately can be customized without recompiling the code.

When returning custom objects (like the arrays returned by the CascadingDropDown web methods), the objects are serialized using object names, including their namespace. While my collections were only a few thousand items in length, the unfortunate choice of the long-winded namespace 'AjaxControlToolkit' and class name 'CascadingDropDownNameValue' results in ridiculous object bloat and blows out the default JSON string size by adding the long object name to every single object.

For example, a single City in my array of around 4000 of them is being returned like this:

"__type":"AjaxControlToolkit.CascadingDropDownNameValue","name":"Abanda","value":"2728903","isDefaultValue":false},{"

IMHO it would be much more efficient (and give us programmers less gray hairs!) if shorter names were used, like:

"__type":"AjaxCT.CDDNV","n":"Abanda","v":"2728903","def":false},{"

Or even better, instead of returning an array of objects, return a single object (thus avoiding the namespace.classname overhead in each array element) that contains a string with the data in it. That is exactly what I did in my earlier implementation using Michael Schwartz's AJAX.NET and my own custom code.

In any event, adding the following to my Web.Config solved my issues (so far):

<

system.web.extensions>
<scripting>
<webServices>
<jsonSerializationmaxJsonLength="5000000" />
</webServices>
</scripting>
</system.web.extensions>This link describes Web.Config settings for AJAX:

http://ajax.asp.net/docs/ConfiguringASPNETAJAX.aspx#microsoftweb

This forum thread was also helpful:

http://forums.asp.net/thread/1634922.aspx

No comments:

Post a Comment