ASP DOT NET

基于web开发的技术研究

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);
    }
}
 
阅读更多
个人分类: AJAX
想对作者说点什么? 我来说一句

ajax异步提交获取信息示例

2012年11月28日 5KB 下载

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭