您的位置:首页 > 其它

.net2003 使用 Ajax.dll 小结

2007-07-04 15:16 519 查看
重要补充:
重要补充:
Ajax.dll和AjaxPro.dll是两家不同的产品,但用法很类似,对于.net1.1和.net2.0
需要不同的dll支持!!
Ajax.dll官网:http://ajax.schwarz-interactive.de/csharpsample/default.aspx
AjaxPro.dll官网:http://www.ajaxpro.info/
两者使用比较:ajax两组件之对比(ajax.dll,ajaxpro.dll)http://blog.csdn.net/nicewon/archive/2007/04/06/1554460.aspx


最近由于任务需要不得不重新接触.net2003但是要使用到javascript,而又感觉.net代码很乱,不好跟JS交互,所以使用了Ajax.dll来帮助简化,以下是简单的总结,希望对大家有用!

简单流程:

viewplaincopytoclipboardprint?测试环境:
XP+.Net2003+Ajax.dll5.7.22.2

1>.net项目添加引用Ajax.dll
2>在web.config文件里按如下格式添加配置:
(说明:这里是指定一个虚拟路径以动态给出js文件下载地址)
<configuration>
<system.web>
<httpHandlers>
<addverb="POST,GET"path="ajax/*.ashx"type="Ajax.PageHandlerFactory,Ajax"/>
</httpHandlers>
...
<system.web>
</configuration>

3>在一个类(任意类)里实现一个Ajax方法:
usingSystem;

namespacezhAjax{
publicclassAjaxTest{
publicAjaxTest(){}
[Ajax.AjaxMethod]//Ajax方法
publicintsum(inta,intb){
returna+b;
}
}
}

4>在一个aspx页面的codebehind代码中的Page_Load()方法中加入如下代码:
privatevoidPage_Load(objectsender,System.EventArgse){
//在当前页面中注册服务器端的Ajax方法,注册的类是zhAjax.AjaxTest
//其中zhAjax是命名空间,AjaxTest是类名。
Ajax.Utility.RegisterTypeForAjax(typeof(zhAjax.AjaxTest));
}

5>在aspx页面里包含自己用到的JS文件,两个内容如下:
aspx文件:
<%@Pagelanguage="c#"Codebehind="Z.aspx.cs"AutoEventWireup="false"Inherits="zhAjax.WebForm2"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML><HEAD>
<title>WebForm2</title>
<metaname="GENERATOR"Content="MicrosoftVisualStudio.NET7.1">
<metaname="CODE_LANGUAGE"Content="C#">
<metaname="vs_defaultClientScript"content="JavaScript">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
<scripttype=text/javascriptlanguage=javascriptsrc='js.js'></script>
<!--注意:自己引入的JS标签一定要有单独的结尾标签</script>,否则将会出现
ajax_request为定义的现象,应为IE6将其其后的html都当作javascript了,
同时要注意自己的Javascript不要出现任何错误-->
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
A:<inputid=asize=15><br>
B:<inputid=bsize=15><br>
SUM:<inputid=sumsize=15><br>
<inputtype=buttonvalue='计算'onclick="myFunc()"><br>
</form>
</body>

</HTML>
js文件:js.js
functionmyFunc(){
AjaxTest.sum(
document.getElementById("a").value,
document.getElementById("b").value,
callback
);
}
functioncallback(ret){
document.getElementById("sum").value=ret.value;
}
viewplaincopytoclipboardprint?usingSystem;
usingSystem.Web;
namespaceCSharpSample
{
///<summary>
///SummarydescriptionforMethods.
///</summary>
publicclassDemoMethods
{
[Ajax.AjaxMethod]
publicstaticstringTest1(stringfirstName,stringfamilyName,stringemail,stringcomment)
{
return"Hello"+firstName+""+familyName+"<br>Thankyouforyourcomment("
+DateTime.Now.ToString()+"):<br><b>"+System.Web.HttpUtility.HtmlEncode(comment).Replace("/r","<br>")+"</b>.";
}
[Ajax.AjaxMethod]
publicstringTest2(DateTimed)
{
d=d.AddDays(1);
return"Thenextdaywillbe"+d.ToLongDateString()+".";
}
[Ajax.AjaxMethod]
publicSystem.Data.DataSetTest3()
{
System.Data.DataSetds=newSystem.Data.DataSet();
System.Data.DataTabledt=newSystem.Data.DataTable();
dt.Columns.Add("Country",typeof(System.String));
ds.Tables.Add(dt);
System.Data.DataRowrow;

//fillsampledata(i.e.canbereplacedwithdatabasequery)

row=ds.Tables[0].NewRow();
row["Country"]="Germany";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="Austria";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="Switzerland";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="France";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="Bavaria;)";
dt.Rows.Add(row);

returnds;
}
[Ajax.AjaxMethod]
publicvoidTest4()
{
thrownewSystem.Security.SecurityException("Thisuserdoesnothaveaccessrightsonthisresource.");
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
publicvoidTest5(stringvalue)
{
HttpContext.Current.Session["test"]=value;
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
publicstringTest6()
{
if(HttpContext.Current.Session["test"]!=null)
return(string)HttpContext.Current.Session["test"];
return"Firstsetthevalue...";
}

[Ajax.AjaxMethod]
publicvoidTest7()
{
intc=0;

do
{
System.Threading.Thread.Sleep(1000);
c++;
}
while(c<10);
}

[Ajax.AjaxMethod]
publicintTest8()
{
Randomr=newRandom(System.DateTime.Now.Second);
returnr.Next(0,100);
}

[Ajax.AjaxMethod]
publicSystem.Collections.Specialized.StringCollectionTest9()
{
System.Collections.Specialized.StringCollections=newSystem.Collections.Specialized.StringCollection();
s.Add("Michael");
s.Add("Hans");
returns;
}
[Ajax.AjaxMethod]
publicobject[]Test10()
{
object[]o=newobject[3];
o[0]="Michael";
o[1]=DateTime.Now;
o[2]=true;
returno;
}
[Ajax.AjaxMethod]
publicSystem.Collections.ArrayListTest11()
{
System.Collections.ArrayLista=newSystem.Collections.ArrayList();
a.Add("Michael");
a.Add(DateTime.Now);
a.Add(true);
Personp1=newPerson();
p1.FirstName="Michael";

SpecialPersonp2=newSpecialPerson();//willbeinheritfromPerson
p2.FirstName="Tanja";
p2.Comment="Mycommentforthisperson!";
a.Add(p1);
a.Add(p2);
returna;
}
[Ajax.AjaxMethod]
publicPersonTest12()
{
//Createyourownclasslikeyouhavedoneitbefore.
//SeePersonclassatendofthisfile!
Personp=newPerson();
p.FirstName="Michael";
p.FamilyName="Schwarz";
p.Age=28;
Personmj=p.NewChild();
mj.FirstName="MarcJulain";
mj.Age=3;
Personjo=p.NewChild();
jo.FirstName="JanOliver";
jo.Age=1;
p.Children=newPerson[2];
p.Children[0]=mj;
p.Children[1]=jo;
//Returntheobjectwithoutanychangeonthesourcecode.
returnp;
}
[Ajax.AjaxMethod]
publicNewsTickerTest13()
{
NewsTicker[]nt=newNewsTicker[10];
#regionBuildsomeexamples(willbestoredinadatabaseorxmlfile)
nt[0]=newNewsTicker("Ajax.NETLibrary","http://ajax.schwarz-interactive.de",4);
nt[1]=newNewsTicker("GoogleSearch","http://www.google.com",2);
nt[2]=newNewsTicker("Itisnow"+DateTime.Now.ToString(),"http://ajax.schwarz-interactive.de",4);
nt[3]=newNewsTicker("ASP.NETWeblogs","http://weblogs.asp.net/mschwarz",3);
nt[4]=newNewsTicker("FreeAjax.NETWrapper","http://weblogs.asp.net/mschwarz",4);
nt[5]=newNewsTicker("NewC#examplesonline!","http://ajax.schwarz-interactive.de",3);
nt[6]=newNewsTicker("PC-Topp.NETDemo","http://demo.pctopp.com",2);
nt[7]=newNewsTicker("NEWAjax.NETLibrary","http://ajax.schwarz-interactive.de",4);
nt[8]=newNewsTicker("Downloadajax.dll","http://ajax.schwarz-interactive.de",2);
nt[9]=newNewsTicker("FreeDownload!!","http://ajax.schwarz-interactive.de",2);
#endregion
Randomr=newRandom(System.DateTime.Now.Second);
inti=r.Next(0,nt.Length-1);
returnnt[i];
}
[Ajax.AjaxMethod]
publicSystem.Data.DataSetTest15()
{
System.Data.SqlClient.SqlConnectionconn=newSystem.Data.SqlClient.SqlConnection("server=(local);uid=??;password=????;InitialCatalog=Northwind;");
System.Data.SqlClient.SqlCommandcmd=newSystem.Data.SqlClient.SqlCommand("SELECTTOP10*FROMCustomersCINNERJOINOrdersOONO.CustomerID=C.CustomerID",conn);

System.Data.SqlClient.SqlDataAdapterda=newSystem.Data.SqlClient.SqlDataAdapter(cmd);
System.Data.DataSetds=newSystem.Data.DataSet();
try
{
conn.Open();
try
{
da.Fill(ds);
}
catch(Exception)
{}
finally
{
conn.Close();
conn.Dispose();
}
}
catch(Exception)
{}
returnds;
}
[Ajax.AjaxMethod]
publicSystem.Drawing.BitmapTest16()
{
System.Drawing.Bitmapbmp=newSystem.Drawing.Bitmap(200,50);
System.Drawing.Graphicsg=System.Drawing.Graphics.FromImage(bmp);

g.FillRectangle(newSystem.Drawing.SolidBrush(System.Drawing.Color.Yellow),0,0,199,49);
g.DrawString(DateTime.Now.ToString(),newSystem.Drawing.Font("Arial",10),newSystem.Drawing.SolidBrush(System.Drawing.Color.Red),10,10);
returnbmp;
}
[Ajax.AjaxMethod]
publicintTest17(int[]i)
{
intr=0;
foreach(intiiini)
r+=ii;
returnr;
}
[Ajax.AjaxMethod]
publicstringTest18(string[]s)
{
stringr="";
foreach(stringssins)
r+="<p>"+ss+"</p>/r/n";
returnr;
}
[Ajax.AjaxMethod]
publicSystem.Web.UI.HtmlControls.HtmlSelectTest19(stringcar)
{
System.Web.UI.HtmlControls.HtmlSelectcontrol=newSystem.Web.UI.HtmlControls.HtmlSelect();
switch(car)
{
case"VW":
control.Items.Add("Golf");
control.Items.Add("Passat");
control.Items.Add("Beetle");
control.Items.Add("Phaeton");
break;
case"Mercedes":
control.Items.Add("SClass");
control.Items.Add("EClass");
control.Items.Add("AClass");
control.Items.Add("MClass");
break;
case"Citroen":
control.Items.Add("C3Pluriel");
control.Items.Add("C5Break");
control.Items.Add("C8");
control.Items.Add("Berlingo");
break;
}
returncontrol;
}
[Ajax.AjaxMethod(30)]
publicSystem.DateTimeTest20()
{
returnDateTime.Now;
}
[Ajax.AjaxMethod]
publicSystem.Web.UI.HtmlControls.HtmlSelectTest21(System.Web.UI.HtmlControls.HtmlSelectselect)
{
select.Items.Add("Newoptionaddedat"+DateTime.Now);
returnselect;
}
[Ajax.AjaxMethod]
publicSystem.Xml.XmlDocumentTest22()
{
System.Xml.XmlDocumentdoc=newSystem.Xml.XmlDocument();
doc.LoadXml("<ROOT/>");
doc.DocumentElement.InnerText=DateTime.Now.ToString();
returndoc;
}
}

[Serializable]
publicclassNewsTicker
{
publicGuidID=Guid.NewGuid();
publicNewsTicker(stringtext,stringurl,intduration)
{
this.Text=text;
this.URL=url;
this.Duration=duration;
}
publicstringText;
publicstringURL;
publicintDuration=60;
}
[Serializable]
publicclassPerson//:System.Collections.CollectionBase
{
publicstringFirstName;
publicstringFamilyName;
publicintAge=0;
publicdecimalMoney=200.5m;
publicPersonNewChild()
{
Personp=newPerson();
p.FamilyName=FamilyName;
returnp;
}
publicPerson[]Children=null;
#regionCollectionBaseMethods
//publicPersonthis[intindex]
//{
//get{return((Person)List[index]);}
//set{List[index]=value;}
//}
//
//publicintAdd(Personvalue)
//{
//return(List.Add(value));
//}
//
//publicintIndexOf(Personvalue)
//{
//return(List.IndexOf(value));
//}
//
//publicvoidInsert(intindex,Personvalue)
//{
//List.Insert(index,value);
//}
//
//publicvoidRemove(Personvalue)
//{
//List.Remove(value);
//}
//
//publicboolContains(Personvalue)
//{
////IfvalueisnotoftypeInt16,thiswillreturnfalse.
//return(List.Contains(value));
//}
//
//protectedoverridevoidOnInsert(intindex,Objectvalue)
//{
//if(value.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("valuemustbeoftypeCSharpSample.Person.","value");
//}
//
//protectedoverridevoidOnRemove(intindex,Objectvalue)
//{
//if(value.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("valuemustbeoftypeCSharpSample.Person.","value");
//}
//
//protectedoverridevoidOnSet(intindex,ObjectoldValue,ObjectnewValue)
//{
//if(newValue.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("newValuemustbeoftypeCSharpSample.Person.","newValue");
//}
//
//protectedoverridevoidOnValidate(Objectvalue)
//{
//if(value.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("valuemustbeoftypeCSharpSample.Person.");
//}
#endregion
}
[Serializable]
publicclassSpecialPerson:Person
{
publicstringComment="";
}
[Serializable]
publicclassIAjaxObjectSource
{
publicstringTitle="";
publicstringFilename="";
publicIAjaxObjectSource(stringtitle,stringfilename)
{
Title=title;
Filename=filename;
}
}
}
usingSystem;
usingSystem.Web;
namespaceCSharpSample
{
///<summary>
///SummarydescriptionforMethods.
///</summary>
publicclassDemoMethods
{
[Ajax.AjaxMethod]
publicstaticstringTest1(stringfirstName,stringfamilyName,stringemail,stringcomment)
{
return"Hello"+firstName+""+familyName+"<br>Thankyouforyourcomment("
+DateTime.Now.ToString()+"):<br><b>"+System.Web.HttpUtility.HtmlEncode(comment).Replace("/r","<br>")+"</b>.";
}
[Ajax.AjaxMethod]
publicstringTest2(DateTimed)
{
d=d.AddDays(1);
return"Thenextdaywillbe"+d.ToLongDateString()+".";
}
[Ajax.AjaxMethod]
publicSystem.Data.DataSetTest3()
{
System.Data.DataSetds=newSystem.Data.DataSet();
System.Data.DataTabledt=newSystem.Data.DataTable();
dt.Columns.Add("Country",typeof(System.String));
ds.Tables.Add(dt);
System.Data.DataRowrow;

//fillsampledata(i.e.canbereplacedwithdatabasequery)

row=ds.Tables[0].NewRow();
row["Country"]="Germany";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="Austria";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="Switzerland";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="France";
dt.Rows.Add(row);
row=ds.Tables[0].NewRow();
row["Country"]="Bavaria;)";
dt.Rows.Add(row);

returnds;
}
[Ajax.AjaxMethod]
publicvoidTest4()
{
thrownewSystem.Security.SecurityException("Thisuserdoesnothaveaccessrightsonthisresource.");
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
publicvoidTest5(stringvalue)
{
HttpContext.Current.Session["test"]=value;
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
publicstringTest6()
{
if(HttpContext.Current.Session["test"]!=null)
return(string)HttpContext.Current.Session["test"];
return"Firstsetthevalue...";
}

[Ajax.AjaxMethod]
publicvoidTest7()
{
intc=0;

do
{
System.Threading.Thread.Sleep(1000);
c++;
}
while(c<10);
}

[Ajax.AjaxMethod]
publicintTest8()
{
Randomr=newRandom(System.DateTime.Now.Second);
returnr.Next(0,100);
}

[Ajax.AjaxMethod]
publicSystem.Collections.Specialized.StringCollectionTest9()
{
System.Collections.Specialized.StringCollections=newSystem.Collections.Specialized.StringCollection();
s.Add("Michael");
s.Add("Hans");
returns;
}
[Ajax.AjaxMethod]
publicobject[]Test10()
{
object[]o=newobject[3];
o[0]="Michael";
o[1]=DateTime.Now;
o[2]=true;
returno;
}
[Ajax.AjaxMethod]
publicSystem.Collections.ArrayListTest11()
{
System.Collections.ArrayLista=newSystem.Collections.ArrayList();
a.Add("Michael");
a.Add(DateTime.Now);
a.Add(true);
Personp1=newPerson();
p1.FirstName="Michael";

SpecialPersonp2=newSpecialPerson();//willbeinheritfromPerson
p2.FirstName="Tanja";
p2.Comment="Mycommentforthisperson!";
a.Add(p1);
a.Add(p2);
returna;
}
[Ajax.AjaxMethod]
publicPersonTest12()
{
//Createyourownclasslikeyouhavedoneitbefore.
//SeePersonclassatendofthisfile!
Personp=newPerson();
p.FirstName="Michael";
p.FamilyName="Schwarz";
p.Age=28;
Personmj=p.NewChild();
mj.FirstName="MarcJulain";
mj.Age=3;
Personjo=p.NewChild();
jo.FirstName="JanOliver";
jo.Age=1;
p.Children=newPerson[2];
p.Children[0]=mj;
p.Children[1]=jo;
//Returntheobjectwithoutanychangeonthesourcecode.
returnp;
}
[Ajax.AjaxMethod]
publicNewsTickerTest13()
{
NewsTicker[]nt=newNewsTicker[10];
#regionBuildsomeexamples(willbestoredinadatabaseorxmlfile)
nt[0]=newNewsTicker("Ajax.NETLibrary","http://ajax.schwarz-interactive.de",4);
nt[1]=newNewsTicker("GoogleSearch","http://www.google.com",2);
nt[2]=newNewsTicker("Itisnow"+DateTime.Now.ToString(),"http://ajax.schwarz-interactive.de",4);
nt[3]=newNewsTicker("ASP.NETWeblogs","http://weblogs.asp.net/mschwarz",3);
nt[4]=newNewsTicker("FreeAjax.NETWrapper","http://weblogs.asp.net/mschwarz",4);
nt[5]=newNewsTicker("NewC#examplesonline!","http://ajax.schwarz-interactive.de",3);
nt[6]=newNewsTicker("PC-Topp.NETDemo","http://demo.pctopp.com",2);
nt[7]=newNewsTicker("NEWAjax.NETLibrary","http://ajax.schwarz-interactive.de",4);
nt[8]=newNewsTicker("Downloadajax.dll","http://ajax.schwarz-interactive.de",2);
nt[9]=newNewsTicker("FreeDownload!!","http://ajax.schwarz-interactive.de",2);
#endregion
Randomr=newRandom(System.DateTime.Now.Second);
inti=r.Next(0,nt.Length-1);
returnnt[i];
}
[Ajax.AjaxMethod]
publicSystem.Data.DataSetTest15()
{
System.Data.SqlClient.SqlConnectionconn=newSystem.Data.SqlClient.SqlConnection("server=(local);uid=??;password=????;InitialCatalog=Northwind;");
System.Data.SqlClient.SqlCommandcmd=newSystem.Data.SqlClient.SqlCommand("SELECTTOP10*FROMCustomersCINNERJOINOrdersOONO.CustomerID=C.CustomerID",conn);

System.Data.SqlClient.SqlDataAdapterda=newSystem.Data.SqlClient.SqlDataAdapter(cmd);
System.Data.DataSetds=newSystem.Data.DataSet();
try
{
conn.Open();
try
{
da.Fill(ds);
}
catch(Exception)
{}
finally
{
conn.Close();
conn.Dispose();
}
}
catch(Exception)
{}
returnds;
}
[Ajax.AjaxMethod]
publicSystem.Drawing.BitmapTest16()
{
System.Drawing.Bitmapbmp=newSystem.Drawing.Bitmap(200,50);
System.Drawing.Graphicsg=System.Drawing.Graphics.FromImage(bmp);

g.FillRectangle(newSystem.Drawing.SolidBrush(System.Drawing.Color.Yellow),0,0,199,49);
g.DrawString(DateTime.Now.ToString(),newSystem.Drawing.Font("Arial",10),newSystem.Drawing.SolidBrush(System.Drawing.Color.Red),10,10);
returnbmp;
}
[Ajax.AjaxMethod]
publicintTest17(int[]i)
{
intr=0;
foreach(intiiini)
r+=ii;
returnr;
}
[Ajax.AjaxMethod]
publicstringTest18(string[]s)
{
stringr="";
foreach(stringssins)
r+="<p>"+ss+"</p>/r/n";
returnr;
}
[Ajax.AjaxMethod]
publicSystem.Web.UI.HtmlControls.HtmlSelectTest19(stringcar)
{
System.Web.UI.HtmlControls.HtmlSelectcontrol=newSystem.Web.UI.HtmlControls.HtmlSelect();
switch(car)
{
case"VW":
control.Items.Add("Golf");
control.Items.Add("Passat");
control.Items.Add("Beetle");
control.Items.Add("Phaeton");
break;
case"Mercedes":
control.Items.Add("SClass");
control.Items.Add("EClass");
control.Items.Add("AClass");
control.Items.Add("MClass");
break;
case"Citroen":
control.Items.Add("C3Pluriel");
control.Items.Add("C5Break");
control.Items.Add("C8");
control.Items.Add("Berlingo");
break;
}
returncontrol;
}
[Ajax.AjaxMethod(30)]
publicSystem.DateTimeTest20()
{
returnDateTime.Now;
}
[Ajax.AjaxMethod]
publicSystem.Web.UI.HtmlControls.HtmlSelectTest21(System.Web.UI.HtmlControls.HtmlSelectselect)
{
select.Items.Add("Newoptionaddedat"+DateTime.Now);
returnselect;
}
[Ajax.AjaxMethod]
publicSystem.Xml.XmlDocumentTest22()
{
System.Xml.XmlDocumentdoc=newSystem.Xml.XmlDocument();
doc.LoadXml("<ROOT/>");
doc.DocumentElement.InnerText=DateTime.Now.ToString();
returndoc;
}
}

[Serializable]
publicclassNewsTicker
{
publicGuidID=Guid.NewGuid();
publicNewsTicker(stringtext,stringurl,intduration)
{
this.Text=text;
this.URL=url;
this.Duration=duration;
}
publicstringText;
publicstringURL;
publicintDuration=60;
}
[Serializable]
publicclassPerson//:System.Collections.CollectionBase
{
publicstringFirstName;
publicstringFamilyName;
publicintAge=0;
publicdecimalMoney=200.5m;
publicPersonNewChild()
{
Personp=newPerson();
p.FamilyName=FamilyName;
returnp;
}
publicPerson[]Children=null;
#regionCollectionBaseMethods
//publicPersonthis[intindex]
//{
//get{return((Person)List[index]);}
//set{List[index]=value;}
//}
//
//publicintAdd(Personvalue)
//{
//return(List.Add(value));
//}
//
//publicintIndexOf(Personvalue)
//{
//return(List.IndexOf(value));
//}
//
//publicvoidInsert(intindex,Personvalue)
//{
//List.Insert(index,value);
//}
//
//publicvoidRemove(Personvalue)
//{
//List.Remove(value);
//}
//
//publicboolContains(Personvalue)
//{
////IfvalueisnotoftypeInt16,thiswillreturnfalse.
//return(List.Contains(value));
//}
//
//protectedoverridevoidOnInsert(intindex,Objectvalue)
//{
//if(value.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("valuemustbeoftypeCSharpSample.Person.","value");
//}
//
//protectedoverridevoidOnRemove(intindex,Objectvalue)
//{
//if(value.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("valuemustbeoftypeCSharpSample.Person.","value");
//}
//
//protectedoverridevoidOnSet(intindex,ObjectoldValue,ObjectnewValue)
//{
//if(newValue.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("newValuemustbeoftypeCSharpSample.Person.","newValue");
//}
//
//protectedoverridevoidOnValidate(Objectvalue)
//{
//if(value.GetType()!=Type.GetType("CSharpSample.Person"))
//thrownewArgumentException("valuemustbeoftypeCSharpSample.Person.");
//}
#endregion
}
[Serializable]
publicclassSpecialPerson:Person
{
publicstringComment="";
}
[Serializable]
publicclassIAjaxObjectSource
{
publicstringTitle="";
publicstringFilename="";
publicIAjaxObjectSource(stringtitle,stringfilename)
{
Title=title;
Filename=filename;
}
}
}

default.js
[code]viewplaincopytoclipboardprint?functioncallback_test1(res)
{
document.getElementById("display1").innerHTML=res.value;
}
functiontest1()
{
DemoMethods.Test1(
document.getElementById("firstName").value,
document.getElementById("familyName").value,
document.getElementById("email").value,
document.getElementById("comment").value,
callback_test1
);
}
functioncallback_test2(res)
{
document.getElementById("display2").innerHTML=res.value;
}
functiontest2()
{
vard=null;
try
{
d=newDateTime(
document.getElementById("year").value,
document.getElementById("month").value,
document.getElementById("day").value,
0,0,0
);

DemoMethods.Test2(d,callback_test2);
}
catch(e)
{
alert("Error:"+e.description);
}
}
functioncallback_test3(res)
{
if(res!=null&&res.value!=null&&res.value.Tables!=0&&res.value.Tables.length==1)
{
varhtml=[];

for(vari=0;i<res.value.Tables[0].Rows.length;i++)
html[html.length]="<option>"+res.value.Tables[0].Rows[i].Country+"</option>";

document.getElementById("display3").innerHTML="<select>"+html.join("")+"</select>";
}
}
functiontest3()
{
DemoMethods.Test3(callback_test3);
}
functiontest4()
{
varres=DemoMethods.Test4();
if(res.error!=null)alert(res.error);
}
functiontest5()
{
DemoMethods.Test5(document.getElementById("sessionTest1").value);
}
functioncallback_test6(res)
{
document.getElementById("sessionTest2").value=res.value;
}
functiontest6()
{
DemoMethods.Test6(callback_test6);
}
functioncallback_test7(res)
{
alert("Theserverhasfinishedthe10secondscall,now!");
}
functiontest7()
{
DemoMethods.Test7(callback_test7);
}
functiontest8(ele)
{
DemoMethods.Test8(test8_callback,ele);//theserver-sidemethodhasnoarguments!
}
functiontest8_callback(res)
{
if(res.error==null&&res.context!=null)
res.context.innerHTML=res.value;
}
functiontest11()
{
DemoMethods.Test11(test11_callback);
}
functiontest11_callback(res)
{
if(res.value[2])//bolean
alert(res.value[1].toLocaleString());//date

alert(res.value[3].FirstName+"+"+res.value[4].FirstName);
}
functiontest12()
{
DemoMethods.Test12(test12_callback);
}
functiontest12_callback(res)
{
vars=res.value.FirstName+""+res.value.FamilyName+":/r/n";

for(vari=0;i<res.value.Children.length;i++)
s+="/t"+res.value.Children[i].FirstName+"/r/n";

alert(s);
}
functiontest13()
{
//calltheAjax.NETmethodontheservertoget
//anewnewstickerobject

DemoMethods.Test13(test13_callback);
}
functiontest13_callback(res)
{
if(typeof(res.value)=='object')
{
//displaythenewsticker

document.getElementById('newsticker').innerHTML='<ahref="'+res.value.URL+'">'+res.value.Text+'</a>';
window.setTimeout(test13,res.value.Duration*1000);
}
}
functiontest16()
{
DemoMethods.Test16(test16_callback);
}
functiontest16_callback(res)
{
if(typeof(res.value)=='object')
{
document.getElementById("imageholder").innerHTML='';
document.getElementById("imageholder").appendChild(res.value);
}
}
functiontest17(n)
{
//nwillbeaarrayofnumbers/integer
if(typeof(n)!='object')return;
alert(DemoMethods.Test17(n).value);
}
functiontest18()
{
alert(DemoMethods.Test18(["aaaa","bbbb","ccc/"ccccc"]).value);
}
functiontest19(ele,car)
{
HtmlControlUpdate('DemoMethods.Test19','dropDisplay',car);
}
functiontest20()
{
returnDemoMethods.Test20().value;
}
functiontest21(controlHolderId,id)
{
HtmlControlUpdate('DemoMethods.Test21',controlHolderId,newHtmlControl(id));
}
window.attachEvent("onload",test13);

functioncallback_test1(res)
{
document.getElementById("display1").innerHTML=res.value;
}
functiontest1()
{
DemoMethods.Test1(
document.getElementById("firstName").value,
document.getElementById("familyName").value,
document.getElementById("email").value,
document.getElementById("comment").value,
callback_test1
);
}
functioncallback_test2(res)
{
document.getElementById("display2").innerHTML=res.value;
}
functiontest2()
{
vard=null;
try
{
d=newDateTime(
document.getElementById("year").value,
document.getElementById("month").value,
document.getElementById("day").value,
0,0,0
);

DemoMethods.Test2(d,callback_test2);
}
catch(e)
{
alert("Error:"+e.description);
}
}
functioncallback_test3(res)
{
if(res!=null&&res.value!=null&&res.value.Tables!=0&&res.value.Tables.length==1)
{
varhtml=[];

for(vari=0;i<res.value.Tables[0].Rows.length;i++)
html[html.length]="<option>"+res.value.Tables[0].Rows[i].Country+"</option>";

document.getElementById("display3").innerHTML="<select>"+html.join("")+"</select>";
}
}
functiontest3()
{
DemoMethods.Test3(callback_test3);
}
functiontest4()
{
varres=DemoMethods.Test4();
if(res.error!=null)alert(res.error);
}
functiontest5()
{
DemoMethods.Test5(document.getElementById("sessionTest1").value);
}
functioncallback_test6(res)
{
document.getElementById("sessionTest2").value=res.value;
}
functiontest6()
{
DemoMethods.Test6(callback_test6);
}
functioncallback_test7(res)
{
alert("Theserverhasfinishedthe10secondscall,now!");
}
functiontest7()
{
DemoMethods.Test7(callback_test7);
}
functiontest8(ele)
{
DemoMethods.Test8(test8_callback,ele);//theserver-sidemethodhasnoarguments!
}
functiontest8_callback(res)
{
if(res.error==null&&res.context!=null)
res.context.innerHTML=res.value;
}
functiontest11()
{
DemoMethods.Test11(test11_callback);
}
functiontest11_callback(res)
{
if(res.value[2])//bolean
alert(res.value[1].toLocaleString());//date

alert(res.value[3].FirstName+"+"+res.value[4].FirstName);
}
functiontest12()
{
DemoMethods.Test12(test12_callback);
}
functiontest12_callback(res)
{
vars=res.value.FirstName+""+res.value.FamilyName+":/r/n";

for(vari=0;i<res.value.Children.length;i++)
s+="/t"+res.value.Children[i].FirstName+"/r/n";

alert(s);
}
functiontest13()
{
//calltheAjax.NETmethodontheservertoget
//anewnewstickerobject

DemoMethods.Test13(test13_callback);
}
functiontest13_callback(res)
{
if(typeof(res.value)=='object')
{
//displaythenewsticker

document.getElementById('newsticker').innerHTML='<ahref="'+res.value.URL+'">'+res.value.Text+'</a>';
window.setTimeout(test13,res.value.Duration*1000);
}
}
functiontest16()
{
DemoMethods.Test16(test16_callback);
}
functiontest16_callback(res)
{
if(typeof(res.value)=='object')
{
document.getElementById("imageholder").innerHTML='';
document.getElementById("imageholder").appendChild(res.value);
}
}
functiontest17(n)
{
//nwillbeaarrayofnumbers/integer
if(typeof(n)!='object')return;
alert(DemoMethods.Test17(n).value);
}
functiontest18()
{
alert(DemoMethods.Test18(["aaaa","bbbb","ccc/"ccccc"]).value);
}
functiontest19(ele,car)
{
HtmlControlUpdate('DemoMethods.Test19','dropDisplay',car);
}
functiontest20()
{
returnDemoMethods.Test20().value;
}
functiontest21(controlHolderId,id)
{
HtmlControlUpdate('DemoMethods.Test21',controlHolderId,newHtmlControl(id));
}
window.attachEvent("onload",test13);


[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: