我有一个用户控件,它在子页面上作为模式弹出窗口打开。弹出窗口中有一个文本框,我正在验证重复值,因为我已经编写了以下服务器端和客户端函数。
function Check_DuplicateMachineType() {
var hndDuplicateMachineType = document.getElementById('<%= hndDuplicateMachineType.ClientID %>');
var txtmachineType = document.getElementById('<%= txtmachineType.ClientID %>');
if (txtmachineType.value.trim() != '' && txtmachineType.value.trim().toLowerCase() != hndDuplicateMachineType.value) {
$.ajax({
type: "POST",
url: "wucMachineType.ascx/CheckDuplicateMachineType",
data: '{Item: "' + $("#<%=txtmachineType.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessForMachineType,
failure: function(response) {
alert(response);
}
});
}
}
function OnSuccessForMachineType(response) {
var txtmachineType = document.getElementById('<%= txtmachineType.ClientID %>');
var divMachineTypes = document.getElementById('<%= divMachineTypes.ClientID %>');
divMachineTypes.innerHTML = '';
switch (response.d) {
case "true":
divMachineTypes.style.display = "inline";
divMachineTypes.innerHTML = "Machine Type already exist";
$("#<%=divMachineTypes.ClientID%>")[0].focus();
$("#<%=hndIsDuplicate.ClientID%>")[0].value = '1';
break;
case "false":
$("#<%=hndIsDuplicate.ClientID%>")[0].value = '0';
break;
case "error":
divMachineTypes.style.display = "inline";
divMachineTypes.innerHTML = "Error occured";
break;
}
}
[System.Web.Services.WebMethod]
public static string CheckDuplicateMachineType(string Item)
{
CommonClass objCLSCommon = new CommonClass();
DataLayer dtLayer = new DataLayer();
try
{
string strQuery = "SELECT machineType from MachineType Where machineType ='" + Item + "'";
DataTable dtCheckDuplicacy = dtLayer.Get_GeneralData(strQuery);
if (dtCheckDuplicacy.Rows.Count > 0)
{
return "true";
}
else
{
return "false";
}
}
catch (Exception ex)
{
objCLSCommon.LogErrorToFile(objCLSCommon.GetCurrentPageName(), ex.Message.Trim() + Environment.NewLine + ex.StackTrace.Trim());
return "";
}
}
我不知道为什么我的wucMachineType.ascx/CheckDuplicateMachineType
函数没有被调用。错误控制台中也没有错误。