AjaxPro的使用方法汇总_第1页
AjaxPro的使用方法汇总_第2页
AjaxPro的使用方法汇总_第3页
AjaxPro的使用方法汇总_第4页
AjaxPro的使用方法汇总_第5页
已阅读5页,还剩5页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、AjaxPro的使用方法简单介绍下它的用法:一.AjaxPro的使用1 .在项目中添加引用,浏览找到 AjaxPro.2.dll文件2 .在 Web.config中的system.web里面写入以下代码</configuration><system.web><httpHandlers><add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/> </httpHandlers></sys

2、tem.web></configuration>3 .在加载事件中,加入AjaxPro.Utility.RegisterTypeForAjax(typeof(类名);4 .写的方法都要用AjaxPro.AjaxMethod开头,然后在写方法5 .调用时必须写清楚命名空间名.类名方法,例:WebUI._Default.getData();6 .调用可分两中方法(同步调用,异步调用)在后台写的无参方法AjaxPro.AjaxMethodpublic string getStr() (return "hello my friends")在后台写的有参方法Ajax

3、Pro.AjaxMethodpublic string getString(string str) (return str + "Say: hello my friends")a.同步调用.拖入html控件button(2) .双击,自动显示在.aspx的脚本中(3) .在里面写入你要输入的内容 例:/ 同步调用无参 function Button1_onclick() (var res=WebUI._Default.getStr();alert(res.value);)/同步调用有参function Button2_onclick() /TextBoxl为服务器控件(va

4、r str=document.getElementById("<%=TextBox1.ClientID%>").value;var res=WebUI._Default.getStr(str);alert(res.value);b.异步调用.拖入html控件button(2) .双击,自动显示在.aspx的脚本中(3) .在里面写入你要输入的内容例:/异步调用无参 function Button3_onclick() WebUI._Default.getStr(getStrCallBack);function getStrCallBack(res)alert(r

5、es.value);/异步调用有参function Button4_onclick() var str=document.getElementById("<%=TextBox1.ClientID %>").value;WebUI._Default.getString(str,getStringCallBack);function getStringCallBack(res)alert(res.value);7 .调用对象/对象AjaxPro.AjaxMethodpublic Class getClass() Class cla = new Class();cla

6、.C_Id = 100;cla.C_Name = "34 班";cla.Count = 20;return cla;/ 同步调用对象 function Button5_onclick() var res=WebUI._Default.getClass().value;alert("班级编号:"+res.C_Id+"名称:"+res.C_Name+"人数:"+res.Count); / 异步调用对象 function Button6_onclick() WebUI._Default.getClass(getClass

7、CallBack);)function getClassCallBack(clas)var res=clas.value;alert("班级编号:"+res.C_Id+"名称:"+res.C_Name+"人数:"+res.Count);)8 .数据集的使用方法AjaxPro.AjaxMethodpublic DataSet getInfo() return WebUI.GetDataSet.getList();)/异步调用数据集function Button8_onclick() WebUI._Default.getInfo(getD

8、ataSetCallBack);)function getDataSetCallBack(res)var dataset=res.value;var strHtml=""strHtml +='<table style ="border-collapse:collapse ; border-color:Gray ;" border="1px">'strHtml +=' <tr>'strHtml +=' <td> 学生编号 </td>'strH

9、tml +=' <td> 名称 </td>'strHtml +=' <td> 年龄 </td>'strHtml +=' </tr>'for(var i=0;i<dataset.Tables0.Rows.length;i+) strHtml +=' <tr>'strHtml +=' <td>'+ dataset.Tables0.Rowsi.stu_id +'</td>'strHtml +='

10、<td>'+ dataset.Tables0.Rowsi.stu_name +'</td>'strHtml +=' <td>'+ dataset.Tables0.Rowsi.stu_age +'</td>'strHtml +=' </tr>')strHtml +=' </table>'thedata.innerHTML=strHtml;/thedata 是一个 <div id="thedata"><

11、/div> 中的 thedata )9 .验证码的使用/ 验证码的使用(必须采用同步调用)/验证码的使用AjaxPro.AjaxMethodpublic bool ValidCodeData(string code) (return (HttpContext.Current.Session"CheckCode".ToString()=code);)function Button9_onclick() var code=document.getElementById("<%=TextBox2.ClientID %>").value;var

12、 bool=WebUI._Default.V alidCodeData(code).value;if(bool=true) alert("ok");elsealert("no");AjaxPro.dll文件网上很多的,自己下,如果找不到呢,给我发个留言,我发你邮箱二,直接调用:javascript 中:<%=后台方法 %> function says()alert("<%=Say()%>");function del()alert("<%=DeleteByID(8)%>");/D

13、eleteByID(8)后台方法名三,采用 ICallbackEventHandler 回调必须声明 System.Web.UI.ICallbackEventHandler 接口public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler/定义一个回调的返回值private string Result;/定义两个变量,用来接收页面传过来到操作数private string Num1;private string Num2;protected void Page_Load(objec

14、t sender, EventArgs e) / <summary>/该方法是回调执行的方法,根据参数在这个方法中处理回调的内容,该方法没有返回值/ </summary>/ <param name="eventArgument"> 此参数是从客户端传过来的</param>public void RaiseCallbackEvent(string eventArgument)/eventArgumeng为javascript从客户端传递的参数,本例传过来三个参数用“盼割将每个参数取出存入数组string PagParams =

15、eventArgument.Split('/');Num1 = PagParams1;Num2 = PagParams2;根据第一个参数(所选的操作符),调用不同的执行函数switch (PagParams0) case "0":Result = add(); break;case "1":Result = sub(); break;case "2":Result = multi(); break;case "3":Result = division(); break; / <summary&

16、gt;/该方法是返回回调的结果给客户端/ </summary>/ <returns></returns>public string GetCallbackResult() return Result;/一下四个函数是通过RaiseCallbackEvent方法,调用的回调要执行操作的函数private string add()double addResult = double.Parse(Num1) + double.Parse(Num2); return addResult.ToString(); private string sub() double a

17、ddResult = double.Parse(Num1) - double.Parse(Num2); return addResult.ToString(); private string multi() double addResult = double.Parse(Num1) * double.Parse(Num2); return addResult.ToString(); private string division() double addresult = double.Parse(Numl) / double.Parse(Num2);return addresult.ToStr

18、ing();)VS2005中AJAX使用方法声明一个AJAX命名空间Ajax_showPL,在每个类定义之前加上此句。(注意: Web2.0不支持命名空间, 他把所有的类都放在自己生成的App_Code文件夹中)AjaxPro. AjaxNamespace( "Ajax_showPL")/ HT_ShowPL_Q偈一个类,在这个类中注册AJAX远程处理方法,把这句代码加在页面加载的事件中。这里用到了反射(反射是.NET中获取运行时类型信息的方式,让程序员可以在程序运行期获得程序集,模块, 类的相关信息)AjaxPro. Utility .RegisterTypeForAja

19、x( typeof (HT_ShowPL_QT/声明AJAX方法,在每个AJAX方法前面加上此句代码。AjaxPro. AjaxMethod /同时,要在 Web.config配置文件中做相应的修改。<?xml version =" 1.0" encoding ="gb2312" ?><!-注意:除了手动编辑此文件以外,您还可以使用Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的“网站” -> “Asp.Net配置”选项。设置和注释的完整列表在ments 中,该文件通常位于WindowsMicros

20、oft.NetFrameworkv2.xConfig中-><configuration ><!-AJAX 配置 begin= -><configSections ><sectionGroup name=" ajaxNet " ><!-If you are using Microsoft .NET 1.1 please remove the two attributes requirePermission and restartOnExternalChanges, they are only supported wi

21、th .NET 2.0.-><section name=" ajaxSettings "type ="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2 " requirePermission ="false " restartOnExternalChanges ="true "/></ sectionGroup ></ configSections ><ajaxNet ><ajaxSettings ><u

22、rlNamespaceMappings useAssemblyQualifiedName =" false " ><!-Set the attribute useAssemblyQualifiedName to true to enable use of assemblies placed in the GAC by using the full assembly qualified name.To hide internal knowledge of assemblies, classes and namespace you can override the

23、name of the virtual http endpoints.<add type="Namespace.Class1,Assembly" path="mypath" />-></ urlNamespaceMappings ><jsonConverters ><!-This section can be used to add new IJavaScriptConverters to the Ajax.NET Professional engine. If you want to disable bu

24、ilt-in converters you can use the remove tag.<remove type="Namespace.Class1,Assembly"/><add type="Namespace.Class2,Assembly"/>-></ jsonConverters ><!-Set the enabled attribute to true to get Stack, TargetSize and Source information if an exception has been

25、 thrown.-><debug enabled =" true " /><!-This is the default configuration used with Ajax.NET Professional. You can put there your static JavaScript files, or remove the path attribute to completly disable the files.<scriptReplacements><file name="core" path=&

26、quot;/ajaxpro/core.ashx" /><file name="prototype" path="/ajaxpro/prototype.ashx" /><file name="converter" path="/ajaxpro/converter.ashx" /> </scriptReplacements>-><!- <encryption cryptType="" keyType="" /&

27、gt;-><!-Set the enabled attribute to true to enable the use of an Ajax.NET Professional token. This will send a token to the client that will be used to identify if therequests comes from the same PC. -><token enabled =" false " sitePassword =" password" /><!-Th

28、e oldStyle section can be used to enable old styled JavaScript code or functions that are not used any more.<oldStyle><objectExtendPrototype/><appCodeQualifiedFullName/></oldStyle> -></ ajaxSettings ></ ajaxNet ><!- Handler configuration for Ajax.NET Profess

29、ional-><location path =" ajaxpro " ><system.web ><httpHandlers ><add verb="*" path =" *.ashx " type ="AjaxPro.AjaxHandlerFactory,AjaxPro.2 "/> </ httpHandlers > <!-If you need to have Ajax.NET Professional methods running on

30、 the login page you may have to enable your own authorization configuration here.-><!-<authorization><deny users="?"/></authorization>-></ system.web ></ location ><!-If you are using Ajax.NET Professional with forms authentication you may need to

31、allow ASP.NET to have access to following three files.-><location path="ajaxpro/prototype.ashx"><system.web><authorization><allow users="*"/></authorization></system.web></location><location path="ajaxpro/core.ashx"><

32、;system.web><authorization><allow users="*"/></authorization></system.web></location><location path="ajaxpro/converter.ashx"><system.web><authorization><allow users="*"/></authorization></system.web>&l

33、t;/location>><!-AJAX 配置 over=< appSettings ><add key-' Connectstring " value ="server=100ZZ-1SQLEXPRESS;database=my_wxfl;user id=bbbb;password=bbbb "/>< add key ="open_Log" value 1" />< add key =" local_url" value =""

34、;/></ appSettings ><connectionStrings /><system.web ><!-设置compilation debug="true"将调试符号插入已编译的页面中。但由于这会影响性能,因此只在开发过程中将此值设置为true ocompilation debug-'true "><assemblies ><add assembly =" System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089" /><add assembly =" System.Design, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /><add assembly =" System.Management, Version=, Culture=neutral, PublicKeyTok

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论