C#2.0下面的简单Ajax应用

使用AjaxPro实现异步调用
本文介绍如何利用AjaxPro库在ASP.NET中实现异步调用功能,包括无参数及带参数的方法调用,并展示了具体的代码实现过程。
不带参数的:
Default.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default ));   
    }  
    [AjaxMethod]
    public string GetString()
    {
        return "test...";
    }   
}
 
Default.aspx invoke:
<script>
function GetString()
{
   Default .GetString(GetString_Callback); // asynchronous call
}
function GetString_Callback(response)
{
   if(response != null)
   {
       window.document.getElementById("TextBox1").value = response.value;         
   }
   else
   {
       window.document.getElementById("TextBox1").value= "";  
   } 
}
GetString();
</script>
带参数的:
Default.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));   
    }  
    [AjaxMethod]
    public string GetString(string str)
    {
        return str;
    }   
}
 
Default.aspx invoke:
<script>
function GetString()
{
   Default .GetString("test",GetString_Callback); // asynchronous call contain param
}
function GetString_Callback(response)
{
   if(response != null)
   {
       window.document.getElementById("TextBox1").value = response.value;         
   }
   else
   {
       window.document.getElementById("TextBox1").value= "";  
   } 
}
GetString();
</script>

转载于:https://www.cnblogs.com/zhuangjunx/archive/2006/08/22/483039.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值