[Anthem.NET]在UserControl中使用回调(CallBack)
在一般的页面(aspx)中,我们可以使用Anthem_InvokePageMethod方法回调页面上的方法,具体的调用方式请参考:http://www.cnblogs.com/RChen/archive/2006/09/12/anthem_callback.html。
那么该如何在UserControl中实现回调呢?请使用Anthem_InvokeControlMethod。
该方法包含四个参数:
Anthem_InvokeControlMethod(
userControlID, // 用户控件ID
'MethodName', // 服务器方法名
[], // 以数组形式传入参数
function(result) {
// 回调结束后的客户端行为方法
}
);
userControlID, // 用户控件ID
'MethodName', // 服务器方法名
[], // 以数组形式传入参数
function(result) {
// 回调结束后的客户端行为方法
}
);
例子:
a.ascx
<script>
function CallBackTest()
{
Anthem_InvokeControlMethod(<%= ClientID %>, "ClickMe", [], function(result){alert("You have clicked me " + result + " times!");}
}
</script>
<input type="button" onclick="Javascript:CallBackTest();" />
function CallBackTest()
{
Anthem_InvokeControlMethod(<%= ClientID %>, "ClickMe", [], function(result){alert("You have clicked me " + result + " times!");}
}
</script>
<input type="button" onclick="Javascript:CallBackTest();" />
a.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
Anthem.Manager.Register(this);
if(!IsPostBack)
{
ViewState["Times"] = 0;
}
}
[Anthem.Method]
public int ClickMe()
{
return Convert.ToInt32(ViewState["Times"]) + 1;
}
{
Anthem.Manager.Register(this);
if(!IsPostBack)
{
ViewState["Times"] = 0;
}
}
[Anthem.Method]
public int ClickMe()
{
return Convert.ToInt32(ViewState["Times"]) + 1;
}
获取更多关于Anthem的使用方法:http://anthem.talloaksoftware.com/Default.aspx