views:

30

answers:

0

I get a method error 500 on my dropdown. I've seen other posts, but those solutions did not work for me. Strange thing is that if I call the webservice outside the page (directly) I do get the desired response. But via the dropdown it seems that the webservice is not even called...

Here's my code:

<asp:DropDownList ID="ddlCountries" runat="server">
</asp:DropDownList> <cc1:cascadingdropdown ID="cddCountries" runat="server" Category="Country" Enabled="True" LoadingText="Loading...please wait." PromptText="Choose a country" ServiceMethod="GetCountries" ServicePath="~/LocalCities.asmx" TargetControlID="ddlCountries">
</cc1:cascadingdropdown>

LocalCities.asmx:

<%@ WebService Language="VB" CodeBehind="~/App_Code/LocalCities.vb" Class="GeoLocs" %>

LocalCities.vb:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports AjaxControlToolkit
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient

<WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> <System.Web.Script.Services.ScriptService()> _ Public Class GeoLocs Inherits System.Web.Services.WebService

<WebMethod()> _ Public Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue() Dim values As New List(Of CascadingDropDownNameValue)

    Dim myConnection As SqlConnection = GetConnection()
    Dim cmd As New SqlCommand("SELECT * FROM countries", myConnection)
    Try
        myConnection.Open()
        Dim reader As SqlDataReader = cmd.ExecuteReader
        Dim CountryName As String
        Dim CountryID As Integer
        While reader.Read
            CountryName = reader("title").ToString
            Int32.TryParse(reader("id"), CountryID)
            values.Add(New CascadingDropDownNameValue(CountryName, CountryID.ToString))
        End While
    Catch ex As Exception
    Finally
        myConnection.Close()
    End Try

    Return values.ToArray
End Function

End Class