.net之AJAX实践-更新等待实践

来源:互联网 发布:javascript日期格式化 编辑:程序博客网 时间:2024/06/06 07:23
 

在登录126邮箱时,如果时间过长,就会有一个登录动态图标显示。当然过快你可能都看不见,一闪而过。查看资料发现这个功能是通过AJAX技术来实现的。 

在VS2005下使用AJAX,访问http://ajax.asp.net/获取详细信息。微软的Atlas官方网站。

1 下载ASPAJAX扩展包:

http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f4%2f6%2f5462bcbd-e738-45fa-84ca-fa02b0c4e1c2%2fASPAJAXExtSetup.msi

2 下载AjaxControlToolkit.zip

同样在该网站有下.

3 关于页面更新时显示动画图标的讲解

http://download.microsoft.com/download/a/1/3/a134c3ec-8244-4099-af4d-b18a6bf7ee32/HDI-AJAX-UpdateProgress.wmv

4 代码(C#)的,不过网站同时也提供其它形式的代码。同时有大量的关于AJAX的实例讲解和代码。

http://download.microsoft.com/download/a/1/3/a134c3ec-8244-4099-af4d-b18a6bf7ee32/HDI-AJAX-UpdateProgress-CS.zip

5 我的测试:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <ProgressTemplate>
                    <img src="indicator_mozilla_blu.gif" />系统正在处理 请稍后...
                </ProgressTemplate>
            </asp:UpdateProgress>
        </div>
        &nbsp;
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                &nbsp; 密码:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <br />
                密码确认:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>   
</body>
</html>

6 对应的cs代码:

using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //System.Threading.Thread.Sleep(3000);

       // 下面是模拟处理过程

        int j = 0;
        for (int i = 0; i < 100000000; i++)
        {
            j = i+j;
       
        }
            if (TextBox1.Text.Equals(TextBox2.Text))
            {
                Response.Redirect("/login.aspx");
            }
            else
            {
                Response.Redirect("/error.aspx");
            }
      
    }
}

7 图标下载地址

http://www.napyfab.com/ajax-indicators/

http://www.ajaxload.info/

测试通过

推荐去处:http://hi.baidu.com/yeqijiao/blog/item/9da307971c65366c54fb964f.html

http://www.cnblogs.com/dflying/archive/2006/04/01/363998.aspx

http://ajax.asp.net/docs/default.aspx

原创粉丝点击