【发布时间】:2013-12-24 07:30:20
【问题描述】:
我的 .cs 代码是
auth_reg.aspx.cs (breakpoint shows the method is never reached)
[WebMethod]
public void ImageButton1_Click()
{
string strScript = "<script language='JavaScript'>alert('working')</script>";
Page.RegisterStartupScript("PopUp", strScript);
}
.html代码
<asp:ImageButton ID="imgbtnsave" runat="server" Text="Submit" ImageUrl="images/btn-submit1.jpg" src="images/btn-submit1.jpg" onmouseout="this.src='images/btn-submit1.jpg';" onmouseover="this.src='images/btn-submit.jpg';" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#imgbtnsave').click(function () {
$.ajax({
type: "POST",
url: "auth_reg.aspx/ImageButton1_Click",
data: '{}',
contentType: "application/json",
dataType: "json",
success: function (msg) {
alert('workingajax');
},
error: function () {
alert('error');
}
});
});
</script>
我的代码没有调用,页面只是在点击时刷新
【问题讨论】:
-
你找到答案了吗?
-
作为 ashx 页面我们可以做到这一点
标签: c# asp.net ajax jquery webmethod