为了使服务器端函数在javascript中可用,必须做两件事情,首先,要使用的函数必须标有Ajax.AjaxMethodAttribute.其次,在页加载事件期间,必须通过调用Ajax.Utility.RegisterTypeForAjax来注册包含这些函数的类。

private void Page_Load(object sender, System.EventArgs e)
{
//注册我们感兴趣的包含服务器端函数
//的类
Ajax.Utility.RegisterTypeForAjax(typeof(Sample));
}
[Ajax.AjaxMethod()]
public string GetMessageOfTheDay()
{
return "Experience is the mother of wisdom";
}
}

首先告知Ajax.Net在Sample类  中查找Ajax方法。

 

<script  language="javascript">

Sample.GetMessageOfTheDay(GetMessageOfTheDay_CallBack);

function  GetMessageOfTheDay_CallBack(response)

{

 alert (response.value);

}

posted on 2010-11-09 13:45  挑战自我  阅读(142)  评论(0编辑  收藏  举报