这是采用Ajax技术,刷新是肯定的,是在我们察觉不到的速度完成.XMLHTTP牺牲页面的方法,我们之所以看不见刷新,是因为所有的工作都是在牺牲页面上进行的,里面"翻江倒海"的"折腾",我们看不见,效率上差些!
,wt1&i. AjaxPro.dll 下载地址
http://ajaxpro.schwarz-interactive.de/download/ajaxpro.zip #8]&-*A2 'g%@"B*)Y Web.Config
v;Ao <?xml version="1.0"?>
F@NF8*au <configuration>
V7w1od< <system.web>
`d-r1pE <httpHandlers>
vC[#> 'Q x <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
uLyuDxv <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
/\2k^h5UwX </httpHandlers>
F<=p5ie </system.web>
g}hJoGK H </configuration>
r[+f.D.+I s"pS1n;o0 AjaxTest.aspx
*[a~!{}U Da:>k"w/ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="AjaxTest" %>
=x1&!2 :zKmO'/" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
45+$g} ^LMX]9J <html xmlns="
http://www.w3.org/1999/xhtml" >
Zj:ipz i` <head runat="server">
^G}@;e 19 <title>无标题页</title>
!Os`5l( wKK1j4 I </head>
8;>=SBl >T:ouc|w< <body>
e #;?M&k8K <script language="javascript" type="text/javascript">
%dvY ? function areaResult()
f!M> F` s {
MesRNA? var area=document.getElementById("DropDownList1");
r65BuHG`r //alert(area.value);
oob_S< AjaxTest.GetCityList(area.value,get_city_Result_CallBack);
NWu? # }
^!18ng2 function get_city_Result_CallBack(response)
?1f0&A {
Ihf~(xO$ if (response.value != null)
,Uzt%/LY {
28PyFcrQ&: document.all("DropDownList2").length=0;
>1l|<'+) var ds = response.value;
:/4}-Q~ if(ds != null && typeof(ds) == "object" && ds.Tables != null)
~Ve%38"LT {
'RL<wRMV for(var i=0; i<ds.Tables[0].Rows.length; i++)
b'L#n6TZJ {
1ANJt/M> var name=ds.Tables[0].Rows
.name; y$efq8LG
var id=ds.Tables[0].Rows.id; HR ;!]Q
document.all("DropDownList2").options.add(new Option(name,id)); 3v >f3
} tr@jO j;
//document.all("TextBox1").value=""; rgSyz5e
} U l4 <S?
} vA.lsu~3~
return qCeS2mS<
} sN8(z `>
,0]H 5<\L
</script> 8ic3fbk
<form id="form1" runat="server"> jdkhE:
$tvuT$,5d{
<asp:DropDownList ID="DropDownList1" runat="server"> (aj8&(%<&
</asp:DropDownList> 5*EgS fa
<asp:DropDownList ID="DropDownList2" runat="server"> 'Ax 3 >
</asp:DropDownList> s" NI
<br /> SU9`TW` `,
</form> \6poO%pip
</body> eIuU"7
</html> G)>`+4/K
{JQ DW L3
AjaxTest.cs ^O%CAjGU
7tGwmXe
using System; /tO OX\"
using System.Data; JbuO;
using System.Configuration; Ve8KOKhn
using System.Collections; iMv#( 6%
using System.Web; sZ'z!}n1Y*
using System.Web.Security; nvO)\*
using System.Web.UI; 0 P3[1G&
using System.Web.UI.WebControls; c(KO\o3pM
using System.Web.UI.WebControls.WebParts; }O>JI>S3B%
using System.Web.UI.HtmlControls; G%L _quY0
using MeetWeb; ` FOH4_
public partial class AjaxTest : System.Web.UI.Page =y7nDD;%1
{ eBQ>K6hKFs
protected void Page_Load(object sender, EventArgs e) 4Pr%b-XK
{ xt$:,IQ2
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxTest)); o5X\5aw
if (!Page.IsPostBack) @r0j9Rr,G
{ N-"I\Sv
BindData(); "2WCB;O%3
u>eB b'
} ,{ <%:}vW
} } q*P-\f
private void BindData() x7 AxL e
{ f%f @UN;2
DataSet ds = new DataSet(); 3&~:@X
String sql = "Select id,name from test"; Hjo *}-
try klhvQ2 mk
{ 'Rg:n}C/g
ds = GetDataSet(sql, "test"); iE[u+{M^
this.DropDownList1.DataSource = ds.Tables[0]; O];S^tUfY
this.DropDownList1.DataTextField = "name"; z}y ml
this.DropDownList1.DataValueField = "id"; )9|,=Pk
this.DropDownList1.DataBind(); |S4).3qQ
this.DropDownList1.Attributes.Add("onclick", "areaResult();"); am=Z3TJ
} *G ,y 7\va
catch (Exception ex) [aM%Oay
{ HqG - ~a
Response.Write(ex.Message); Sx5xPo_J
} %`G><q~hv
} Hz945ZH
Q=G;v]q<
public static DataSet GetDataSet(string sql,string aa) pmd<"vJJ
{ 8VoN$jP}/
MeetWeb.SqlDataBase a = new MeetWeb.SqlDataBase("server=localhost\\PMSERVER;uid=sa;pwd=sa;database=test"); a["G8TG
DataSet ds = new DataSet(); |m=]n
ds=a.CreateSet(sql, aa); $t AK q=V
return ds; VaqdIm_
} #\Hz;d_
<aCq8 =]
[AjaxPro.AjaxMethod] 'g a9 Zn
public DataSet GetCityList(int id) uc.,s
{ )+Iq
string sql = "select name from test where id='" + id + "'"; 9fJe}>?
return GetDataSet(sql,"test"); ' (i9Zp
} !z&]V}Tk
IoI+2/C
q'=aM<
}