简单应用ajaxPro

1.webConfig 中配置一下

 

System.web 下

    <httpHandlers>
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
    </httpHandlers>

 

2.Page_Load 里进行时注册

AjaxPro.Utility.RegisterTypeForAjax(typeof(_AjaxPro));

 

3.创建服务器端方法。方法需加上[AjaxPro.AjaxMethod]标记

    [AjaxPro.AjaxMethod]
    public int strName(int num1,int num2)
    {
        int sum = num1 + num2;
        return sum;
    }

4.aspx调用

 

ExpandedBlockStart.gif 代码
<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " AjaxPro.aspx.cs "  Inherits = " _AjaxPro "   %>

<! 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 >
< script type = " text/javascript " >
     function strShow(){
        var num1
= document.getElementById( " num1 " ).value;
        var num2
= document.getElementById( " num2 " ).value;
        var arg
= _AjaxPro.strName(num1,num2).value; // 调用后台方法 继承类名.方法名
            alert(arg);
    }
</ script >
</ head >
< body >
    
< form id = " form1 "  runat = " server " >

        
< div >
            
< asp:TextBox ID = " num1 "  runat = " server "  Text = " 1 " ></ asp:TextBox >
            
< asp:TextBox ID = " num2 "  runat = " server "  Text = " 1 " ></ asp:TextBox >
            
< input type = " button "  runat = " server "  id = " btnSub "  onclick = " strShow(); "  value = " 按钮 "   />
            
</ div >
    
</ form >

</ body >
</ html >

 

 


 

转载于:https://www.cnblogs.com/ziye/archive/2010/01/09/1642764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值