轻松跟学AJAX(一)原创

环境:win2003 sp2 + IE7 + vs2005

作者:孤星浪子

e-mail: landy_di@126.com

博客: lanustudio.bokee.com

时间:2007年8月28日

 

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

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<!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>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <fieldset>
                        <legend>无刷新块</legend>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;
                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="读取数据" /><asp:Label
                            ID="DataLabel" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
                        <asp:Label ID="TextLabel" runat="server" Font-Bold="True" ForeColor="Blue"></asp:Label></fieldset>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
                <ProgressTemplate>
                    <span style=" color:Green;">亲爱的别急,在刷新页面呢..........</span></ProgressTemplate>
            </asp:UpdateProgress>
            <div>
                这个时间可是没有改变哦〖
                <%=DateTime.Now.ToString("hh:mm:ss") %>
                〗
            </div>
        </div>
    </form>
</body>
</html>

 

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

public partial class _Default : System.Web.UI.Page
{
    string conn = WebConfigurationManager.ConnectionStrings["ConnSetting"].ConnectionString;   

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }   
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(5000);
        TextLabel.Text = TextBox1.Text;
        SqlConnection objConnection = new SqlConnection(conn);
        string strSQL = "select * from Test where Title = '" + TextBox1.Text + "'";
        objConnection.Open();
        SqlCommand objCommand = new SqlCommand(strSQL, objConnection);
        SqlDataReader objRead = objCommand.ExecuteReader();
        if (objRead.Read())
        {           
            DataLabel.Text = "恭喜,找到数据!";
        }
        else
        {           
            DataLabel.Text = "可惜,没有找到数据!";
        }
        objConnection.Close();       
    }
}

 

呵呵,很简单的吧?慢慢来,不及的~~~

posted @ 2008-10-23 09:57  Landy_di  阅读(126)  评论(0)    收藏  举报