locked
AJAX Cascading Dropdown using XML Data RRS feed

  • Question

  • User944339287 posted

    hi guys, my dropdownlist returned [Method Error 500]..  may i know what's wrong to my code? pls advise. TQ

    You can download the XML Data file here: northwind.xml

    HTML code for Cascading Dropdown Extender Control

        <asp:ScriptManager ID="ScriptManager1" runat="server">  
        </asp:ScriptManager>  
        <table border="0" cellpadding="2" cellspacing="0" width="500">  
            <tr>  
                <td width="100">  
                    <b>Select Category :</b></td>  
                <td>  
                    <asp:DropDownList ID="drdCategory" runat="server">  
                    </asp:DropDownList>  
                    <cc1:CascadingDropDown  
                    ID="CascadingDropDown1"  
                    runat="server"  
                    Category="category"  
                    TargetControlID="drdCategory"  
                    PromptText="[Select Category]"  
                    ServicePath="~/webservices/cascadingwebservice.asmx"  
                    ServiceMethod="GetDropDownContents">  
                    </cc1:CascadingDropDown>  
                </td>  
            </tr>  
            <tr>  
                <td>  
                    <b>Select Product :</b></td>  
                <td>  
                    <asp:DropDownList ID="drdProduct" runat="server" AutoPostBack="True">  
                    </asp:DropDownList>  
                    <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server"  
                    Category="product"  
                    TargetControlID="drdProduct"  
                    ParentControlID="drdCategory"  
                    PromptText="[Select Product]"  
                    LoadingText="Loading products..."  
                    ServicePath="~/webservices/cascadingwebservice.asmx"  
                    ServiceMethod="GetDropDownContents">  
                    </cc1:CascadingDropDown>  
                </td>  
            </tr> 
        </table>     


    Web Service for CascadingDropdown Extender

    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Xml
    
    
    <WebService(Namespace:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class cascadingwebservice
        Inherits System.Web.Services.WebService
    
        Private Shared _xmlDocument As XmlDocument
        Private documentHierarchy As String() = New String() {"category", "product"}
    
        <WebMethod()> _
        Public Function GetDropDownContents(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue()
            _xmlDocument = New XmlDocument()
            _xmlDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/northwind.xml"))
            Dim knownCategoryValuesDictionary As StringDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
            Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(_xmlDocument, documentHierarchy, knownCategoryValuesDictionary, category)
        End Function
    
    End Class

     

    Friday, August 8, 2014 11:44 PM

Answers

  • User1918509225 posted

    Hi kengkit,

    The url rewrite may enable Enforce Lower Case URLs  you can refer to the link below:

    http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/.

    and you can refer to the link below  has similar issues with yours, which may give your a right direction:

    http://stackoverflow.com/questions/16439120/ajax-cascading-dropdown-with-method-error-500

    Best Regards,

    Kevin Shen.

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 15, 2014 1:56 AM

All replies

  • User-1360095595 posted

    Your webservice class needs to be decorated with the ScriptService attribute. 

    Refer: http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/Walkthrough/CCDWithDB.aspx

    Saturday, August 9, 2014 1:40 AM
  • User944339287 posted

    thanks! just added the following line will do..

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    <System.Web.Script.Services.ScriptService()> _



    Saturday, August 9, 2014 11:56 PM
  • User555306248 posted
    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.
    

    Monday, August 11, 2014 12:21 AM
  • User944339287 posted

    Hi sir,

    I found it's working if i browse at http://localhost:51847/myproject/webpages/member_register.aspx

    it's returned [Method Error 500] if browse at http://localhost:51847/myproject/member/register/   (URL rewriter)

    Please advise. TQ

    Monday, August 11, 2014 12:50 AM
  • User1918509225 posted

    Hi kengkit,

    The url rewrite may enable Enforce Lower Case URLs  you can refer to the link below:

    http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/.

    and you can refer to the link below  has similar issues with yours, which may give your a right direction:

    http://stackoverflow.com/questions/16439120/ajax-cascading-dropdown-with-method-error-500

    Best Regards,

    Kevin Shen.

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 15, 2014 1:56 AM