您的位置:首页 > 编程语言 > ASP

asp.net客户端脚本调用页面方法

2009-11-14 10:27 399 查看
第一步:

将某个页面的方法 有 webmethod attribute;

[WebMethod]
//只能是 public static  的方法
public static DateTime GetCurrentTime()
{
return DateTime.UtcNow;
}


第二步:

页面有一个ScriptManager 设置它的enablepagemethod=true;

asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />


第三步:调用

PageMethods.方法名(回调函数)

<mce:script language="javascript" type="text/javascript"><!--
function getCurrentTime()
{
PageMethods.GetCurrentTime(getCurrentTimeSucceeded);
}

function getCurrentTimeSucceeded(result)
{
alert(result);
}

// --></mce:script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐