现在的位置: 首页 > 综合 > 正文

C#2.0下面的简单Ajax应用

2012年09月01日 ⁄ 综合 ⁄ 共 1249字 ⁄ 字号 评论关闭
不带参数的:
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>

抱歉!评论已关闭.