AJAX提交数据无刷新,“重量级”的实现:ModalUpdateProgress控件。

需要下载 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 %>
                用户名:&nbsp;<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>
         
       
        &nbsp; &nbsp; &nbsp;
        <cc1:modalupdateprogess id="ModalUpdateProgess1" runat="server" associatedupdatepanelid="UpdatePanel1" BackgroundCssClass="modalBackground">
             <ProgressTemplate>
                     <div id="updateAnimation">
                         &nbsp;<img src="../Images/loading1.gif" />Working on your request...
        </div>
            </ProgressTemplate>
       
  
        </cc1:modalupdateprogess>
        &nbsp;<br />
        <br />
        &nbsp;
        </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);
    }
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值