用AjaxPro2遇到的问题

本文介绍了一种简单易懂的AjaxPro.NET使用方法,通过详细步骤指导如何在ASP.NET项目中引入AjaxPro.dll并实现客户端与服务端的交互。演示了如何配置Web.config文件、注册类型、标记[AjaxMethod]属性及客户端调用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

我在写代码时,太马虎 。在客户端少写了.value。真晕
我做了一个超简单的 AjaxProDemo ,发上来供初学者用!!!
步骤如下:
1. 添加 AjaxPro.dll 文件的引用(示例代码中已经包含,直接COPY过来使用即可).

 2. 在Web.config文件中添加以下配置,           

<httpHandlers>             <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />            
</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;
 
 
就可以在客户端直接使用服务端方法, 非常方便, 客户端调用后台代码如下:
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>
 

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>

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;
    }
}

记得要引用AjaxPro.dll文件!!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值