不带参数的:
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>

相关文章:

  • 2022-02-07
  • 2021-10-22
  • 2021-09-17
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-22
  • 2021-08-10
  • 2022-01-07
相关资源
相似解决方案