1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> 3<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"> 4<head runat="server"> 5 <title>无标题页</title> 6</head> 7<body> 8 <form id="form1" runat="server"> 9 <div > 10 <asp:ScriptManager ID="ScriptManager1" runat="server"> 11 12 </asp:ScriptManager> 13 <script language ="javascript"> 14 function ComfirmRefresh() 15 { 16 if(confirm("你确认要刷新吗?")) 17 { 18 //第一个参数是你希望提交到服务器的控件的ID号,第二个参数是事件参数 19 __doPostBack("UpdatePanel1","Refresh"); 20 } 21 } 22 </script> 23 <input id="Button1" type="button" value="button" onclick="ComfirmRefresh()" /> 24 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode ="Conditional"> 25 <ContentTemplate> 26 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 27 </ContentTemplate> 28 </asp:UpdatePanel> 29 </div> 30 </form> 31</body> 32</html>
1public partial class _Default : System.Web.UI.Page 2{ 3 protected void Page_Load(object sender, EventArgs e) 4 { //当前ScriptManager1回发的值是AsyncPostback并且导致ScriptManager1的异步回发事件的控件为UpdatePanel1时。 5 if (ScriptManager1.IsInAsyncPostBack && ScriptManager1.AsyncPostBackSourceElementID == "UpdatePanel1") 6 //label1获取系统当前时间。 7 Label1.Text = DateTime.Now.ToString();