恩,这几天在看着那些大网站的一些Ajax.net的loading的效果,也想写一个,虽然很简单,但容易说明问题。我的这个例子是在登陆的时候显示用户正在登陆的等待信息。同样的使用了AjaxPro.dll。
一,在aspx的页面的代码如下
一,在aspx的页面的代码如下
1
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="ajaxproloading.Default5"
%>
2
3 <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
4
5 < html xmlns ="http://www.w3.org/1999/xhtml" >
6 < head runat ="server" >
7 < title > loaing </ title >
8 < script language =javascript >
9 function Get_Name()
10 {
11 var name=document.getElementById("Text1").value;
12 var pwd=document.getElementById("Text2").value;
13 ajaxproloading.Default5.GetLogin(name,pwd,CallBackServer);
14 document.getElementById("loading").style.display="block";
15
16 }
17 function CallBackServer(res)
18 {
19 var success=res.value;
20 document.getElementById("loading").style.display="none";
21
22 if(success)
23 {
24 document.getElementById("ss").innerHTML="登陆成功";
25
26 }
27 else
28 {
29 document.getElementById("ss").innerHTML="登陆失败";
30 }
31 }
32 </ script >
33 </ head >
34 < body >
35 < form id ="form1" runat ="server" >
36 < div >
37 < input id ="Button1" type ="button" value ="button" onclick ="Get_Name();" />
38 < input id ="Text1" type ="text" />
39 < input id ="Text2" type ="text" /></ div >
40 < div id ="loading" style ="display:none;" >< img src =9.gif /> 正在登陆... </ div >
41 < div id ="ss" ></ div >
42 </ form >
43 </ body >
44 </ html >
45
二,.cs的代码
2
3 <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
4
5 < html xmlns ="http://www.w3.org/1999/xhtml" >
6 < head runat ="server" >
7 < title > loaing </ title >
8 < script language =javascript >
9 function Get_Name()
10 {
11 var name=document.getElementById("Text1").value;
12 var pwd=document.getElementById("Text2").value;
13 ajaxproloading.Default5.GetLogin(name,pwd,CallBackServer);
14 document.getElementById("loading").style.display="block";
15
16 }
17 function CallBackServer(res)
18 {
19 var success=res.value;
20 document.getElementById("loading").style.display="none";
21
22 if(success)
23 {
24 document.getElementById("ss").innerHTML="登陆成功";
25
26 }
27 else
28 {
29 document.getElementById("ss").innerHTML="登陆失败";
30 }
31 }
32 </ script >
33 </ head >
34 < body >
35 < form id ="form1" runat ="server" >
36 < div >
37 < input id ="Button1" type ="button" value ="button" onclick ="Get_Name();" />
38 < input id ="Text1" type ="text" />
39 < input id ="Text2" type ="text" /></ div >
40 < div id ="loading" style ="display:none;" >< img src =9.gif /> 正在登陆... </ div >
41 < div id ="ss" ></ div >
42 </ form >
43 </ body >
44 </ html >
45
1
using
System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
12 namespace ajaxproloading
13 {
14 public partial class Default5 : System.Web.UI.Page
15 {
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 AjaxPro.Utility.RegisterTypeForAjax(typeof(Default5));
19 }
20 [AjaxPro.AjaxMethod]
21 public bool GetLogin(string username,string userpwd)
22 {
23 System.Threading.Thread.Sleep(3000);
24 SqlConnection con = new SqlConnection("server=.;database=testajax;uid=sa;pwd=lanjie");
25 con.Open();
26 SqlCommand com = new SqlCommand();
27 com.CommandText = "select * from userinfo where username='" + username + "' and userpwd='" + userpwd+"'";
28 com.Connection = con;
29 SqlDataReader da = com.ExecuteReader();
30 if (da.Read())
31 {
32 con.Close();
33 return true;
34 }
35 else
36 {
37 con.Close();
38 return false;
39 }
40 }
41 }
42}
43
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
12 namespace ajaxproloading
13 {
14 public partial class Default5 : System.Web.UI.Page
15 {
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 AjaxPro.Utility.RegisterTypeForAjax(typeof(Default5));
19 }
20 [AjaxPro.AjaxMethod]
21 public bool GetLogin(string username,string userpwd)
22 {
23 System.Threading.Thread.Sleep(3000);
24 SqlConnection con = new SqlConnection("server=.;database=testajax;uid=sa;pwd=lanjie");
25 con.Open();
26 SqlCommand com = new SqlCommand();
27 com.CommandText = "select * from userinfo where username='" + username + "' and userpwd='" + userpwd+"'";
28 com.Connection = con;
29 SqlDataReader da = com.ExecuteReader();
30 if (da.Read())
31 {
32 con.Close();
33 return true;
34 }
35 else
36 {
37 con.Close();
38 return false;
39 }
40 }
41 }
42}
43