I am trying to use ajaxToolKit CascadingDropdown with three DropdownList Controls that are being populated from an ASMX WebService. The first dropdown is being populated correctly, but when I select a value on the first dropdown, the child ones are not being populated and breakpoints are not even being hit.

When I test the ASMX WebService using visual studio, I can get the intended results, but when testing the application, the Web Methods that populate the Child Dropdowns are not being called, and the knownCategoryValues parameter, which should contain the key:value for the selected item in the parent dropdown is empty. I assume Ajax is for some reason not sending the selected value, but I cannot find the issue in my code. Any tips would be greatly appreciated.

This is the aspx markup

<div class="card-body">
                <div class="row mb-2 d-flex flex-column">
                    <div class="col">
                        <div class="form-group">
                            <label class="form-label">País</label>

                            <asp:DropDownList ID="ddlPais" runat="server" CssClass="form-select form-select-sm" ></asp:DropDownList>
                            <ajaxToolkit:CascadingDropDown ID="cdlPais" TargetControlID="ddlPais" PromptText="Seleccione País"
                                PromptValue="" ServicePath="~/services/WebService1.asmx" ServiceMethod="GetPaisAcceso"
                                runat="server" Category="CategoryPais" LoadingText="Cargando..." />
                        </div>
                    </div>
                    <div class="col">
                        <div class="form-group">
                            <label class="form-label">Empresa</label>
                            <asp:DropDownList ID="ddlEmpresa" runat="server" CssClass="form-select form-select-sm" ></asp:DropDownList>
                            <ajaxToolkit:CascadingDropDown ID="cdlEmpresa" TargetControlID="ddlEmpresa" PromptText="Seleccione Empresa" PromptValue="" ServicePath="~/services/WebService1.asmx"
                                ServiceMethod="GetEmpresaAcceso" runat="server" ParentControlID="ddlPais" Category="CategoryEmpresa" LoadingText="Cargando..." />
                        </div>
                    </div>
                    <div class="col">
                        <div class="form-group">
                            <label class="form-label">Puesto</label>
                            <asp:DropDownList ID="ddlPuesto" runat="server" CssClass="form-select form-select-sm"></asp:DropDownList>
                            <ajaxToolkit:CascadingDropDown ID="cdlPuesto" TargetControlID="ddlPuesto" PromptText="Seleccione Puesto" PromptValue="" ServicePath="~/services/WebService1.asmx" ServiceMethod="GetPuestoAcceso" ParentControlID="ddlEmpresa" runat="server" Category="CategoryPuesto" LoadingText="Cargando..."  />
                        </div>
                    </div>

                    <div class="col">
                        <hr />
                        <asp:Button ID="btnGuardar" runat="server" CssClass="btn btn-success" OnClick="btnGuardar_OnClick" Text="Guardar Cambios" />
                    </div>
                </div>
            </div>

And the code for the asmx web service

using AjaxControlToolkit;
using FACTURACION_CLASS;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace WebAppVB.services
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class WebService1 : WebService
    {
        private readonly seguridad _seguridad = new seguridad();
        private readonly database _database = new database();

        private string _codigoUser = HttpContext.Current.Request.Cookies["CodigoUser"]?.Value;

        /// <summary>
        /// ?????
        /// </summary>
        /// <param name="knownCategoryValues"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        [WebMethod]
        public CascadingDropDownNameValue[] GetPaisAcceso(string knownCategoryValues)
        {
            string sql = $"SELECT * FROM GetPaisesAccesoUsuario({_codigoUser})";
            List<CascadingDropDownNameValue> paises = GetData(sql);
            return paises.ToArray();
        }

        /// <summary>
        /// ?????
        /// </summary>
        /// <param name="knownCategoryValues"></param>
        /// <returns></returns>
        /// <remarks></remarks>

        [WebMethod]
        public CascadingDropDownNameValue[] GetEmpresaAcceso(string knownCategoryValues)
        {
            string pais = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["CategoryPais"];
            string sql = $"SELECT * FROM GetEmpresasAccesoUsuario({_codigoUser}, {pais})";

            List<CascadingDropDownNameValue> empresas = GetData(sql);
            return empresas.ToArray();
        }

        /// <summary>
        /// ?????
        /// </summary>
        /// <param name="knownCategoryValues"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        [WebMethod]
        public CascadingDropDownNameValue[] GetPuestoAcceso(string knownCategoryValues)
        {
            string empresa = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["CategoryEmpresa"];
            string sql = $"SELECT * FROM GetPuestosAccesoUsuario({_codigoUser}, {empresa})";

            List<CascadingDropDownNameValue> puestos = GetData(sql);
            return puestos.ToArray();
        }

        [WebMethod]
        private List<CascadingDropDownNameValue> GetData(string sql)
        {
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

            using (OleDbConnection dbCon = new OleDbConnection(_seguridad.conn))
            {
                dbCon.Open();

                OleDbCommand cmd = new OleDbCommand(sql, dbCon);
                using (OleDbDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        values.Add(new CascadingDropDownNameValue
                        {
                            name = reader[1].ToString(),
                            value = reader[0].ToString()
                        });
                    }

                    return values;
                }
            }
        }
     }

I tried uninstalling ajaxToolKit and reinstalling, checking my references, I also added a service reference from the web service to my application project.

1

There are 1 best solutions below

0
wazz On

I didn't read everything in detail, but does it help if you add

AutoPostBack="True"

to the DropDownList controls?