有一个带有客户端和服务器端事件的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
答案 0 :(得分:0)
您可以使用jquery trigger():
编辑:从OnClientClick调用CheckApp()函数:
<asp:imagebutton id="imgbtn" runat="server" ImageUrl="/Images/icon.gif" OnClientClick="return CheckAPP();"></asp:imagebutton>
返回true
或false
以触发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;
}
});
}