我有一个我想在客户端调用的c#方法。 我用AJAX调用来实现这个无法使用ajax从javascript调用c#方法
function ValidateIfDuplicate()
{
debugger
var billtext = $("#ctl00_ContentPlaceHolder2_textBoxBillNumber").val();
var retailer= $("#ctl00_ContentPlaceHolder2_dropDownListRetailers").val();
var billdate = $("#ctl00_ContentPlaceHolder2_textBoxBillDate").val();
if (billtext == "")
{
alert("Bill Number cannot be left empty");
return false;
}
else if (retailer == 0) {
alert("Please select a Retailer");
return false;
}
else if (billdate == '') {
alert("Date cannot be left empty");
return false;
}
else if (billtext != '' && retailer != '' && billdate != '')
{
$.ajax({
Type: "POST",
url: "CAInvoiceEntry.aspx/ValidateDuplicateEntry",
contentType: "application/json; charset=utf-8",
data: { billtext1: billtext, billdate1: billdate, retailer1: retailer },
dataType: "json",
success: function (result) {
debugger
alert(result.d);
}
});
return true;
}
}
,这是我的C#方法
[System.Web.Script.Services.ScriptService]
public partial class CAInvoiceEntry: BaseClass
{
[WebMethod, ScriptMethod()]
public static int ValidateDuplicateEntry(string billtext1, string billdate1, string retailer1)
{
string validatebill = objCAInvoiceEntry.validatebilldate(textBoxBillNumber.Text, billdate1.ToString(), ViewState[AppConstants.UploadedBy].ToString(), dropDownListRetailers.SelectedValue);
if (validatebill == "1")
{
return 1;
}
else
return 0;
}
}
但Web方法不被解雇。 我也尝试使用pagemethods.methodname()作为替代方法(通过使用enablepagemethods = true注册脚本),但没有任何效果。
如果有人能指导我在哪里做错了? 在下面的图片中,您可以清楚地看到.. ,您可以看到跳过ajax调用的断点执行。
尝试在此方法所在的类上添加此[System.Web.Script.Services.ScriptService] –
在浏览器的'console'上得到了什么? –
@guruprasad rao没有什么我在浏览器上,当我调试和验证,控制不传递给方法。 –