C#2.0下面的简单Ajax应用

不带参数的:
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>
posted on 2006-08-22 10:23  自由.Net  阅读(283)  评论(0编辑  收藏  举报