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 ));
}
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default ));
}
[AjaxMethod]
public string GetString()
{
return "test...";
}
}
public string GetString()
{
return "test...";
}
}
Default.aspx invoke:
<script>
function GetString()
{
Default .GetString(GetString_Callback); // asynchronous call
}
{
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= "";
}
}
{
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));
}
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
}
[AjaxMethod]
public string GetString(string str)
{
return str;
}
}
public string GetString(string str)
{
return str;
}
}
Default.aspx invoke:
<script>
function GetString()
{
Default .GetString("test",GetString_Callback); // asynchronous call contain param
}
{
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= "";
}
}
{
if(response != null)
{
window.document.getElementById("TextBox1").value = response.value;
}
else
{
window.document.getElementById("TextBox1").value= "";
}
}
GetString();
</script>