可以用到ajax调用服务器端的方法,要么使用服务器端控件
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["op"] == "button2_Click") button2_Click(null, null);
}
private void button2_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('添加成功!');window.location.href='admin.aspx'<" + "/script>");
Response.End();
}
</script>
<html>
<head>
<meta charset="utf-8" />
<title>test</title>
</head>
<body>
<a title="添加至购物车" onclick="button2_Click()">客户端链接</a>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
function button2_Click() {
$.ajax({
url: '',
type: 'POST',
data: { op: 'button2_Click' },
complete: function (xhr) {
alert('服务气端返回内容\n'+xhr.responseText)
}
})
}
</script>
<form runat="server">
<asp:Button runat="server" OnClick="button2_Click" Text="服务器端控件" />
</form>
</body>
</html>
帮助到你能点个采纳吗,谢谢,~~有其他问题可以继续问~