ajaxToolkit:CascadingDropDown 出错
ajaxToolkit:CascadingDropDown got error
我想使用 ajaxtoolkit 创建级联下拉列表,但出现错误。
因为新版本的 ajaxcontroltoolkit 已经删除了 ToolkitScriptManager,所以我使用 scriptmanager
<ajaxToolkit:CascadingDropDown
ID="cdlOffice"
TargetControlID="DropDownList1"
PromptText="Select Office"
PromptValue=""
ServicePath="~/WebService1.asmx"
ServiceMethod="GetLocation"
runat="server"
Category="LocationId"
LoadingText="Loading..." />
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="DropDownList1" CssClass="col-md-2 control-label">Location</asp:Label>
<div class="col-md-10">
<asp:DropDownList id="DropDownList1" runat="server" class="select2-me" data-placeholder="--SELECT--" data-rule-required="true" style="width:250px;" />
</div>
</div>
和WebService1.asmx如下
[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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public CascadingDropDownNameValue[] GetLocation(string knownCategoryValues)
{
string query = "SELECT DISTINCT ITOFF_NAME, ITOFF_ID FROM ITOFF_TBL ORDER BY ITOFF_NAME";
List<CascadingDropDownNameValue> Location = GetData(query);
return Location.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetFloor(string knownCategoryValues)
{
string Location = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["LocationId"];
string query = string.Format("SELECT ITOFF_LEVEL, ITOFF_ID FROM ITOFF_TBL WHERE ITOFF_NAME = {0}", Location);
List<CascadingDropDownNameValue> Floor = GetData(query);
return Floor.ToArray();
}
private List<CascadingDropDownNameValue> GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["ITFORMConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
cmd.Connection = con;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
values.Add(new CascadingDropDownNameValue
{
name = reader[0].ToString(),
value = reader[1].ToString()
});
}
reader.Close();
con.Close();
return values;
}
}
}
}
我在显示时出错
Unhandled exception at line 6, column 97862 in
http://localhost:60461/Scripts/WebForms/MsAjax/MicrosoftAjax.js
0x800a138f - JavaScript runtime error: Unable to get property
'webServiceFailedNoMsg' of undefined or null reference
我从谷歌搜索中学到的所有代码。有没有遗漏或做错了什么?
尝试从您的 getLocation() 网络方法定义中删除字符串参数 'knownCategoryValues':
[WebMethod]
public CascadingDropDownNameValue[] GetLocation()
{
string query = "SELECT DISTINCT ITOFF_NAME, ITOFF_ID FROM ITOFF_TBL ORDER BY ITOFF_NAME";
List<CascadingDropDownNameValue> Location = GetData(query);
return Location.ToArray();
}
并从 Cascading DropDown 定义中删除 locationID 属性。
或者,如果您从另一个下拉列表中获取 locationID,则保留它并将其定义为 ParentControlID
我想使用 ajaxtoolkit 创建级联下拉列表,但出现错误。
因为新版本的 ajaxcontroltoolkit 已经删除了 ToolkitScriptManager,所以我使用 scriptmanager
<ajaxToolkit:CascadingDropDown
ID="cdlOffice"
TargetControlID="DropDownList1"
PromptText="Select Office"
PromptValue=""
ServicePath="~/WebService1.asmx"
ServiceMethod="GetLocation"
runat="server"
Category="LocationId"
LoadingText="Loading..." />
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="DropDownList1" CssClass="col-md-2 control-label">Location</asp:Label>
<div class="col-md-10">
<asp:DropDownList id="DropDownList1" runat="server" class="select2-me" data-placeholder="--SELECT--" data-rule-required="true" style="width:250px;" />
</div>
</div>
和WebService1.asmx如下
[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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public CascadingDropDownNameValue[] GetLocation(string knownCategoryValues)
{
string query = "SELECT DISTINCT ITOFF_NAME, ITOFF_ID FROM ITOFF_TBL ORDER BY ITOFF_NAME";
List<CascadingDropDownNameValue> Location = GetData(query);
return Location.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetFloor(string knownCategoryValues)
{
string Location = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["LocationId"];
string query = string.Format("SELECT ITOFF_LEVEL, ITOFF_ID FROM ITOFF_TBL WHERE ITOFF_NAME = {0}", Location);
List<CascadingDropDownNameValue> Floor = GetData(query);
return Floor.ToArray();
}
private List<CascadingDropDownNameValue> GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["ITFORMConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
cmd.Connection = con;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
values.Add(new CascadingDropDownNameValue
{
name = reader[0].ToString(),
value = reader[1].ToString()
});
}
reader.Close();
con.Close();
return values;
}
}
}
}
我在显示时出错
Unhandled exception at line 6, column 97862 in http://localhost:60461/Scripts/WebForms/MsAjax/MicrosoftAjax.js
0x800a138f - JavaScript runtime error: Unable to get property 'webServiceFailedNoMsg' of undefined or null reference
我从谷歌搜索中学到的所有代码。有没有遗漏或做错了什么?
尝试从您的 getLocation() 网络方法定义中删除字符串参数 'knownCategoryValues':
[WebMethod]
public CascadingDropDownNameValue[] GetLocation()
{
string query = "SELECT DISTINCT ITOFF_NAME, ITOFF_ID FROM ITOFF_TBL ORDER BY ITOFF_NAME";
List<CascadingDropDownNameValue> Location = GetData(query);
return Location.ToArray();
}
并从 Cascading DropDown 定义中删除 locationID 属性。
或者,如果您从另一个下拉列表中获取 locationID,则保留它并将其定义为 ParentControlID