<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="BtnCommon" runat="server" Text="Common" οnclick="Btn_Click" /> <br /> <asp:Button ID="btnPrecedence" runat="server" οnclick="Btn_Click" Text="Precedence" /> <br /> <asp:Label ID="lblmsg" runat="server" ForeColor="#FF3300"></asp:Label> <hr> <div id="divAsyncmsg"></div> </ContentTemplate> </asp:UpdatePanel> <mce:script language="javascript" type="text/javascript"><!-- function ShowMsg(showmsg) { var divAsyncmsg = $get("divAsyncmsg"); divAsyncmsg.innerHTML = showmsg; //现实信息 window.setTimeout(function() { divAsyncmsg.innerHTML=" "}, 3000);//三秒钟后清空 }//异步信息展示 var BtnPrecedenceID = "<%=this.btnPrecedence.ID %>";//获取优先级的按钮ID var BtnLastpostBackID = null;//申明最后一次请求。 Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest( function(sender, e) { var prm = Sys.WebForms.PageRequestManager.getInstance();//获取页面请求实例。 if (prm.get_isInAsyncPostBack()) {//判断是否是异步请求 if (BtnLastpostBackID == BtnPrecedenceID) {//当最后一次请求按钮ID等于优先级别的按钮ID e.set_cancel(true);//取消上一次的postback if (e.get_postBackElement().id == BtnPrecedenceID) {//当点击的按钮等于优先级的按钮ID ShowMsg("重复发起优先级的请求。"); } else {//点击按钮为普通按钮的时候。 ShowMsg("等待优先级的请求结束。"); } } else if (e.get_postBackElement().id == BtnPrecedenceID) {//当点击的按钮为优先级按钮 ShowMsg("现在发起优先级的请求,普通请求将会被取消。"); } else { ShowMsg("重复提交普通级别的请求,上次普通请求将会被取消。");//重复提交普通级别的按钮 } } BtnLastpostBackID = e.get_postBackElement().id; } ); // --></mce:script> </div> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Btn_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(3000); Button btnClick = sender as Button; this.lblmsg.Text = string.Format("当前点击的是{0}按钮。",btnClick.Text); } } 参考:ASP.NET AJAX深入浅出系列课程