需要下载 ModalUpdateProgress控件。自行修改它的AjaxControlTookit.dll的引用位置
前台页面代码!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Post.aspx.cs" Inherits="Demo1_Post" %>
<%@ Register Assembly="ModalUpdateProgress" Namespace="Jeffz.Web" TagPrefix="cc1" %>
<!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 runat="server"> <title>无标题页</title> <style type="text/css"> .modalBackground{ background-color : gray; filter : alpha(opacity=30); opacity : 0.7;}#updateAnimation{ color : Black; background-color : #ffffae; font-family : Arial; font-size : 8pt; font-weight : bold; line-height : 30px; height : 30px; padding-left : 5px; padding-right : 5px;}
</style></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <%= DateTime.Now %> 用户名: <asp:TextBox ID="txt_User" runat="server"></asp:TextBox> <asp:Button ID="btn_Post" runat="server" Text="Button" Width="70px" OnClick="btn_Post_Click" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btn_Post" /> </Triggers> </asp:UpdatePanel> <cc1:modalupdateprogess id="ModalUpdateProgess1" runat="server" associatedupdatepanelid="UpdatePanel1" BackgroundCssClass="modalBackground"> <ProgressTemplate> <div id="updateAnimation"> <img src="../Images/loading1.gif" />Working on your request... </div> </ProgressTemplate>
</cc1:modalupdateprogess> <br /> <br />
</div>
</div> </form></body>
</html>
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.Data.SqlClient;using System.Threading;
cs 文件代码
public partial class Demo1_Post : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } protected void btn_Post_Click(object sender, EventArgs e) { Thread.Sleep(5000); string username=this.txt_User.Text; SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["constr"]);
//throw new Exception("办法"); con.Open(); string sql = "Insert into Xk_User(Reg_Name,sex)values('"+username+"','21')"; SqlCommand cmd = new SqlCommand(sql, con); bool result = Convert.ToBoolean(cmd.ExecuteNonQuery()); if (result) { msgbox("提交成功"); } else { msgbox("提交失败"); } con.Close(); } void msgbox(string msg) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('"+msg+"');", true); }
}