Hi All
Ive been trying to follow tutorials and examples to load drop down lists from cascading drop down AJAX objects, but I started to get mthod error 500 in both my drop downs. I googled method error 500, and i tried following all the different problems that I could
have, but still to no avail.
I'm going to share my code on here, and hopefully someone can help me out or pick up errors that i couldnt see
So the relevant aspx looks like this:
<%@ Page Title="" Language="C#" MasterPageFile="~/MakeReady.Master" AutoEventWireup="true" CodeBehind="createnew.aspx.cs" Inherits="MakeReady.createnew" ValidateRequest="false" EnableEventValidation="false" %>
<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell ID="TableCell6" runat="server"><asp:DropDownList ID="CarTypeDDL" runat="server" width="125px" ></asp:DropDownList>
<ajaxToolkit:CascadingDropDown
ID="CarTypeCDD"
runat="server"
Category="model"
TargetControlID="CarTypeDDL"
PromptText="Choose a Model"
ServicePath="GetService.asmx"
ServiceMethod="GetDropDownContents">
</ajaxToolkit:CascadingDropDown>
</asp:TableCell>
<asp:TableCell ID="TableCell24" runat="server"><asp:DropDownList ID="ModelCodeDDL" runat="server" width="125px" Autopostback="true"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown
ID="CodeCDD"
runat="server"
Category="code"
TargetControlID="ModelCodeDDL"
ParentControlID="CarTypeDDL"
PromptText="Choose a Code"
ServicePath="GetService.asmx"
ServiceMethod="GetDropDownContents">
</ajaxToolkit:CascadingDropDown></asp:TableCell>
</asp:TableRow>
the web method calling in the aspx.cs file looks like this:
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string category)
{
return new GetService().GetDropDownContents(knownCategoryValues, category);
}
and my web service looks like this:
using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
namespace MakeReady
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class GetService : System.Web.Services.WebService
{
private static XmlDocument _document;
private static object _lock = new object();
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{ _document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/modelcodes.xml"));
}
}
return _document;
}
}
1. In WebService add attribute [System.Web.Script.Services.ScriptService()] to class. 2. If you use another asp controls in the same aspx page add in 3. If yet you get error - try ValidateRequest="false" in the tag
before i declare public class GetService : System.Web.Services.WebService {...}?
2. I don't understand what you mean by other asp controls on the aspx page...there are many other asp:controls all over mypage, ranging fro textboxes to drop down lists.
3. which tag?? in my aspx page?
and i tried following the faq, but i dont know how im supposed to run breakpoints in the web service...
never mind, i figured it out!
the example i gave here have both DDL's residing side by side, but in my actual solution, they were in two seperate TableRows in the same Table.
When I put them in the same tablerow, then it all picked up.
I still have NO IDEA as to why that makes a difference, but apparantley TableRows mess around with the functionality in these AJAX controls...
I don't get it. But problem solved.
THANKS FOR YOUR HELP ANYWAYS
Marked as answer by tayseer on May 09, 2012 02:55 PM
Tayseer
Member
39 Points
53 Posts
Getting Method Error 500 when populating Cascading Drop Down
May 04, 2012 01:12 AM|LINK
Hi All
Ive been trying to follow tutorials and examples to load drop down lists from cascading drop down AJAX objects, but I started to get mthod error 500 in both my drop downs. I googled method error 500, and i tried following all the different problems that I could have, but still to no avail.
I'm going to share my code on here, and hopefully someone can help me out or pick up errors that i couldnt see
So the relevant aspx looks like this:
<%@ Page Title="" Language="C#" MasterPageFile="~/MakeReady.Master" AutoEventWireup="true" CodeBehind="createnew.aspx.cs" Inherits="MakeReady.createnew" ValidateRequest="false" EnableEventValidation="false" %> <asp:TableRow ID="TableRow3" runat="server"> <asp:TableCell ID="TableCell6" runat="server"><asp:DropDownList ID="CarTypeDDL" runat="server" width="125px" ></asp:DropDownList> <ajaxToolkit:CascadingDropDown ID="CarTypeCDD" runat="server" Category="model" TargetControlID="CarTypeDDL" PromptText="Choose a Model" ServicePath="GetService.asmx" ServiceMethod="GetDropDownContents"> </ajaxToolkit:CascadingDropDown> </asp:TableCell> <asp:TableCell ID="TableCell24" runat="server"><asp:DropDownList ID="ModelCodeDDL" runat="server" width="125px" Autopostback="true"></asp:DropDownList> <ajaxToolkit:CascadingDropDown ID="CodeCDD" runat="server" Category="code" TargetControlID="ModelCodeDDL" ParentControlID="CarTypeDDL" PromptText="Choose a Code" ServicePath="GetService.asmx" ServiceMethod="GetDropDownContents"> </ajaxToolkit:CascadingDropDown></asp:TableCell> </asp:TableRow> the web method calling in the aspx.cs file looks like this:[WebMethod] [System.Web.Script.Services.ScriptMethod] public static CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string category) { return new GetService().GetDropDownContents(knownCategoryValues, category); }and my web service looks like this:
using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
namespace MakeReady
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class GetService : System.Web.Services.WebService
{
private static XmlDocument _document;
private static object _lock = new object();
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{ _document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/modelcodes.xml"));
}
}
return _document;
}
}
public static string[] Hierarchy
{
get
{
return new string[] { "model", "code" };
}
}
public GetService()
{
}
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
}
}
}
I cant tell what im doing wrong. Help please.
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Getting Method Error 500 when populating Cascading Drop Down
May 05, 2012 08:51 AM|LINK
Hi,
There are three reasons can cause error 500.
1. In WebService add attribute [System.Web.Script.Services.ScriptService()] to class. 2. If you use another asp controls in the same aspx page add in 3. If yet you get error - try ValidateRequest="false" in the tag
Please check the following link about this error: http://www.benhblog.com/2008/09/method-error-500-and-ajax.html
Please refer to this faq which tells you how to locate the cause. It's usually much easier to find it our in your practical environment.
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Tayseer
Member
39 Points
53 Posts
Re: Getting Method Error 500 when populating Cascading Drop Down
May 09, 2012 05:56 AM|LINK
Hi
ok let me ask this:
1. Should i put
[System.Web.Script.Services.ScriptService()]
before i declare public class GetService : System.Web.Services.WebService {...}?
2. I don't understand what you mean by other asp controls on the aspx page...there are many other asp:controls all over mypage, ranging fro textboxes to drop down lists.
3. which tag?? in my aspx page?
and i tried following the faq, but i dont know how im supposed to run breakpoints in the web service...
Tayseer
Member
39 Points
53 Posts
Re: Getting Method Error 500 when populating Cascading Drop Down
May 09, 2012 02:55 PM|LINK
never mind, i figured it out!
the example i gave here have both DDL's residing side by side, but in my actual solution, they were in two seperate TableRows in the same Table.
When I put them in the same tablerow, then it all picked up.
I still have NO IDEA as to why that makes a difference, but apparantley TableRows mess around with the functionality in these AJAX controls...
I don't get it. But problem solved.
THANKS FOR YOUR HELP ANYWAYS