先看看效果:
1 aspx:
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Trigger Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" >
<ProgressTemplate>
<img src="images/loading.gif" alt="loading" style="position:absolute;left:50%;top:50%;"/>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
<asp:Timer ID="Timer1" runat="server" Interval="1" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Trigger Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" >
<ProgressTemplate>
<img src="images/loading.gif" alt="loading" style="position:absolute;left:50%;top:50%;"/>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
<asp:Timer ID="Timer1" runat="server" Interval="1" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
2 CS:
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Timer1.Enabled = true;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Thread.Sleep(3000);
DataTable dt = new DataTable();
DataColumn dcname = new DataColumn("name");
DataColumn dcage = new DataColumn("age");
dt.Columns.Add(dcname);
dt.Columns.Add(dcage);
dt.Rows.Add(new object[]{"engine","25"});
dt.Rows.Add(new object[] { "Water", "30" });
GridView1.DataSource = dt;
GridView1.DataBind();
this.Timer1.Enabled = false;
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Timer1.Enabled = true;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Thread.Sleep(3000);
DataTable dt = new DataTable();
DataColumn dcname = new DataColumn("name");
DataColumn dcage = new DataColumn("age");
dt.Columns.Add(dcname);
dt.Columns.Add(dcage);
dt.Rows.Add(new object[]{"engine","25"});
dt.Rows.Add(new object[] { "Water", "30" });
GridView1.DataSource = dt;
GridView1.DataBind();
this.Timer1.Enabled = false;
}
}