Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

AJAX cascading dropdown not populating - 500 error

$
0
0

NOTE: I asked this question on social.msdn.microsoft.com and was instructed to ask the question here instead.

I have two dropdown controls in a web form and I would like for the results of the second to be dependent upon the value chosen in the first, hence CascadingDropDown AJAX control.

When the page loads I click the first dropdown and get a [Method Error 500].  I have looked at every forum and article I can find and nothing suggested seems to resolve my problem.  I can't even get data into the first dropdown, much less a cascading effect. 

If I attempt to debug and go directly to the ASMX in my browser the GetClients method returns all clients if I enter blank values for both knownCategoryValues and category.

If I attempt to debug and go directly to the ASMX in my browser the GetFileTypesForClient method returns an XML string ArrayOfCascadingDropDownNameValue with no child nodes.

The AJAX controls are registered in web.config.  

When I debug the ASMX method CascadingDropDownNameValue the kv variable contains no items so I have commented it out and figured that I would play with that later.  It does throw the ArgumentException.

Please have a look and see if you can find any stupid mistakes I may have made.

Thanks!

EnterTransaction.aspx

<asp:SqlDataSource runat="server" ID="dsClients" ConnectionString="<%$ ConnectionStrings:INTP1 %>" SelectCommand="SELECT DisplayName, DBName, DisplayName + ' (' + DBName + ')' AS DisplayText, ID FROM DataOperations.dbo.vwClientDatabases ORDER BY DisplayName + ' (' + DBName + ')'" /><asp:SqlDataSource runat="server" ID="dsClientFiles" ConnectionString="<%$ ConnectionStrings:INTP1 %>" SelectCommand="SELECT cf.ClientFileID, cf.DBLIstID, db.DisplayName + ' - ' + clft.LocalFileTypeName AS DisplayText FROM DataOperations.DET.ClientFile AS cf JOIN DataOperations.DET.ClientLocalFileType AS clft ON cf.DBListID = clft.DBListID AND cf.ClientLocalFileTypeID = clft.LocalFileTypeID join DataOperations.dbo.vwClientDatabases db on db.ID = cf.DBListID ORDER BY db.DisplayName + ' (' + db.DBName + ')', LocalFileTypeName" /><asp:SqlDataSource runat="server" ID="dsTransactions" ConnectionString="<%$ ConnectionStrings:INTP1 %>" SelectCommand="SELECT * FROM DataOperations.DET.FileTransaction" /><asp:Table runat="server" ID="tblForm"><asp:TableRow runat="server"><asp:TableCell runat="server" >Client</asp:TableCell><asp:TableCell runat="server" ><asp:DropDownList runat="server" ID="ddlClients" /> <%-- DataSourceID="dsClients" DataValueField="ID" DataTextField="DisplayText" --%><ajaxToolkit:CascadingDropDown ID="cddClients" runat="server"
                     ServicePath="~/ClientFileTypes.cs.asmx" ServiceMethod="GetClients"
                     TargetControlID="ddlClients" Category="Client"
                     PromptText="Select Client..." /></asp:TableCell></asp:TableRow><asp:TableRow runat="server"><asp:TableCell runat="server" >Client File</asp:TableCell><asp:TableCell runat="server" ><asp:DropDownList runat="server" ID="ddlClientFiles" /> <%-- DataSourceID="dsClientFiles" DataValueField="ClientFileID" DataTextField="DisplayText" --%><ajaxToolkit:CascadingDropDown ID="cddClientFiles" runat="server"
                     ServicePath="ClientFileTypes.cs.asmx" ServiceMethod="GetFileTypesForClient"
                     TargetControlID="ddlClientFiles" ParentControlID="ddlClients" LoadingText="Loading..."
                     Category="Client"
                     PromptText="Select File Type..." /></asp:TableCell></asp:TableRow><asp:TableRow runat="server"><asp:TableCell runat="server" >Load Date</asp:TableCell><asp:TableCell runat="server" ><asp:Button runat="server" ID="btnSubmit" Text="Add File Transaction" OnClick="btnSubmit_Click" /></asp:TableCell></asp:TableRow></asp:Table>

ClientFileTypes.asmx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Web.Script.Services;
using AjaxControlToolkit;
using System.Web.Services.Protocols;
using System.Collections.Specialized;
using System.Data.SqlClient;

namespace DETTracker
{
    /// <summary>
    /// Summary description for ClientFileTypes
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class ClientFileTypes : System.Web.Services.WebService
    {
        [WebMethod]
        public CascadingDropDownNameValue[] GetClients(string knownCategoryValues,
            string category)
        {
             SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["INTP1"].ConnectionString);
             sqlConn.Open();
             SqlCommand sqlCmd = new SqlCommand("SELECT DisplayName, DBName, DisplayName + ' (' + DBName + ')' AS DisplayText, ID FROM DataOperations.dbo.vwClientDatabases ORDER BY DisplayName + ' (' + DBName + ')'", sqlConn);
             SqlDataReader dr = sqlCmd.ExecuteReader();
             List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
             while (dr.Read())
             {
                l.Add(new CascadingDropDownNameValue(dr["DisplayText"].ToString(),
                dr["ID"].ToString()));
             }
            sqlConn.Close();

             return l.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] GetFileTypesForClient(string knownCategoryValues,
            string category)
        {
            int nDBListID = -1;
            //StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

            //if (!kv.ContainsKey("Client") || !Int32.TryParse(kv["Client"], out nDBListID))
            //{
            //    throw new ArgumentException("Couldn't find vendor.");
            //};

            bool bReturn = Int32.TryParse(knownCategoryValues, out nDBListID);
            
            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["INTP1"].ConnectionString);
            sqlConn.Open();
            SqlCommand sqlCmd = new SqlCommand("SELECT cf.ClientFileID, cf.DBLIstID, db.DisplayName + ' - ' + clft.LocalFileTypeName AS DisplayText FROM DataOperations.DET.ClientFile AS cf JOIN DataOperations.DET.ClientLocalFileType AS clft ON cf.DBListID = clft.DBListID AND cf.ClientLocalFileTypeID = clft.LocalFileTypeID JOIN DataOperations.dbo.vwClientDatabases db on db.ID = cf.DBListID WHERE db.ID = @DBListID ORDER BY db.DisplayName + ' (' + db.DBName + ')', LocalFileTypeName", sqlConn);
            sqlCmd.Parameters.AddWithValue("@DBListID", nDBListID);
            SqlDataReader dr = sqlCmd.ExecuteReader();
            List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
            while (dr.Read())
            {
                l.Add(new CascadingDropDownNameValue(dr["DisplayText"].ToString(),
                dr["ClientFileID"].ToString()));
            }

            sqlConn.Close();

            return l.ToArray();
        }
    }
}

Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>