我正在尝试使用AJAX填充下拉列表,并且我已经得到方法错误500.我花了一整天时间尝试在几个论坛上找到的所有内容,但似乎没有任何帮助。
如果有人能在这里帮助我,那就太好了。谢谢!
ddl.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ddl.aspx.cs" Inherits="TSS.Administrator.ddl" %>
<%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<div>
<asp:DropDownList ID="ddlCourseLevel" runat="server">
</asp:DropDownList>
<ajax:CascadingDropDown ID="ccdCourseLevel" runat="server" Category="CourseLevel"
TargetControlID="ddlCourseLevel" PromptText="---Select CourseLevel" LoadingText="Loading Countries.."
ServiceMethod="BC" ServicePath="~/WebServices/ws1.asmx">
</ajax:CascadingDropDown>
</div>
</form>
</body>
</html>
ws1.asmx
<%@ WebService Language="C#" CodeBehind="ws1.asmx.cs" Class="TSS.ws1" %>
ws1.asmx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Configuration;
using AjaxControlToolkit;
using System.Web.Script.Services;
namespace TSS
{
/// <summary>
/// Summary description for ws1
/// </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 ws1 : System.Web.Services.WebService
{
dbConnection dbConn = new dbConnection();
[WebMethod]
public CascadingDropDownNameValue[] BC(string knownCategoryValues, string category)
{
DataTable dt = new DataTable();
//CourseLevelDAL _courseLevelDAL = new CourseLevelDAL();
dt = Admin_Course_WebService.PopulateCourseLevel();
//create list and add items in it by looping through dataset table
List<CascadingDropDownNameValue> courseleveldetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dt.Rows)
{
string Name = dtrow["Name"].ToString();
string Id = dtrow["Id"].ToString();
courseleveldetails.Add(new CascadingDropDownNameValue(Name, Id));
}
return courseleveldetails.ToArray();
}
}
}
答案 0 :(得分:0)
我使用了调试工具Fiddler,发现它无法找到Web方法BC,而它无法找到它的原因是因为它是一个静态方法。我将其更改为public并添加了属性[System.Web.Script.Services.ScriptService]。它奏效了!