从客户端单击事件执行jquery ajax调用后触发服务器单击事件

时间:2013-09-01 13:06:39

标签: jquery asp.net ajax vb.net

有一个带有客户端和服务器端事件的asp图像按钮。 客户端方法通过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

1 个答案:

答案 0 :(得分:0)

您可以使用jquery trigger():

编辑:从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;
        }
    });
}