用AjaxPro2遇到的问题
来源:互联网 发布:外贸海关数据 编辑:程序博客网 时间:2024/05/16 14:41
我在写代码时,太马虎 。在客户端少写了.value。真晕
我做了一个超简单的 AjaxProDemo ,发上来供初学者用!!!
步骤如下:
1. 添加 AjaxPro.dll 文件的引用(示例代码中已经包含,直接COPY过来使用即可).
2. 在Web.config文件中添加以下配置,
<httpHandlers> <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
</httpHandlers>
3. 在要使用AjaxPro.NET框架的页面 *.aspx.cs 的 Page_Load事件中加如下代码:
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
4. 经过以上三步骤后, 只要在后台服务端的方法前面增加属性[AjaxMethod]后:
[AjaxMethod()] // or [AjaxPro.AjaxMethod]
public string GetString( string val)
{
return val;
}
public string GetString( string val)
{
return val;
}
就可以在客户端直接使用服务端方法, 非常方便, 客户端调用后台代码如下:
var returnValue = 后台代码类名.GetString(参数);
具体如下:
web.config文件
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
Default.aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
<script type="text/javascript">
function A(v){
var res = _Default.GetString(v);
var val = res.value;
alert(val);
}
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
<!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>
<script type="text/javascript">
function A(v){
var res = _Default.GetString(v);
var val = res.value;
alert(val);
}
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Default.aspx.cs文件:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 AjaxPro;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(_Default) );
TextBox1.Attributes.Add("onblur", "A(this.value);");
}
[AjaxPro.AjaxMethod]
public string GetString(string val)
{
return val;
}
}
using System.Data;
using System.Configuration;
using System.Collections;
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 AjaxPro;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(_Default) );
TextBox1.Attributes.Add("onblur", "A(this.value);");
}
[AjaxPro.AjaxMethod]
public string GetString(string val)
{
return val;
}
}
记得要引用AjaxPro.dll文件!!
- 用AjaxPro2遇到的问题
- 解决AjaxPro2中core.ashx 407缺少对象的问题
- 解决AjaxPro2中core.ashx 407缺少对象的问题
- AjaxPro2 的应用
- AjaxPro2 的应用
- ajaxPro2.0应用时的一些问题(C#)ajax的 (遮罩层)登陆实例
- AjaxPro2中UpdatePanel控件的使用
- ajaxPro2.0和ajaxControl在同一页面使用冲突问题
- 用VC6遇到的问题
- 用VC6遇到的问题
- 用velocity遇到的问题
- 用file_get_contents()遇到的问题
- 用itchat遇到的问题
- 用bootstrap遇到的问题
- AjaxPro2的使用以及iframe的使用(备忘)
- ajaxpro2 调用后台的方法 ajax获取后台的值
- ajaxpro2.0 和服务端交互 传递参数 的实现
- 今天用SQL遇到的问题
- 女生天崩地裂的分手信
- Pro JavaScript Techniques第三章: 创建可重用的代码
- AJAX系列(一)
- iptables处理流程图
- 相信自己
- 用AjaxPro2遇到的问题
- 不错的语段
- CSS制作树状目录代码
- 温故知新的经典--书评《Programming C# 》中文版第4版
- BLFS告一段落-LFS日记6
- 曾友
- gSoap 多线程实验报告( SOAP 协议栈的多线程实验报告)
- 一头驴的生存哲学
- TCP/IP检验和的理解