0

有一个带有客户端和服务器端事件的 asp imagebutton。客户端方法通过 jQuery Ajax 调用 web 方法。在 OnSuccess 事件中,需要触发服务器端事件。

代码片段:

<asp:imagebutton id="imgbtn" runat="server" ImageUrl="/Images/icon.gif" OnClick="return CheckAPP();"></asp:imagebutton>

function CheckAPP() {
    $.ajax({
        type: "POST",
        url: "testPage.aspx/ValidateSerialNumber",
        data: "{strSerialNumber:'" + strSerialNumbers + "',strManufPartNo:'" + strMPartNo + "',strCountryCode:'" + '<%=strCountryCode %>' + "',strIpAddress:'" + '<%=strIpAddress.Trim %>' + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            return true;
        },
        failure: function (msg) {
            return true;
        }
    });
}


Private Sub imgbtn_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtn.Click
  SaveInfo()
End Sub
4

1 回答 1

0

您可以使用 jquery 触发器():

编辑:从 OnClientClick 调用 CheckApp() 函数:

<asp:imagebutton id="imgbtn" runat="server" ImageUrl="/Images/icon.gif" OnClientClick="return CheckAPP();"></asp:imagebutton>

并返回truefalse触发click事件:

function CheckAPP() {
    $.ajax({
        type: "POST",
        url: "testPage.aspx/ValidateSerialNumber",
        data: "{strSerialNumber:'" + strSerialNumbers + "',strManufPartNo:'" + strMPartNo + "',strCountryCode:'" + '<%=strCountryCode %>' + "',strIpAddress:'" + '<%=strIpAddress.Trim %>' + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            return true;
        },
        failure: function (msg) {
            return false;
        }
    });
}
于 2013-09-01T15:44:27.987 回答