现在的位置: 首页 > 综合 > 正文

Ajax Toolkit 控件学习系列(14) ——ScriptManagerProxy

2013年04月17日 ⁄ 综合 ⁄ 共 481字 ⁄ 字号 评论关闭
  • 使用情况:有MasterPage或者自定义的控件时候
  • 使用理由:因为一个页面只有一个ScriptManager,如果MasterPage或者自定义的UserControl使用了,你的页面引入之后,会导致页面有多个ScriptManager,这是不被允许的。
  • 引入:所以我们需要一个代理,代理其实现我们的需要。
  1. 当MasterPage使用ScriptManager的时候,引用的页面中如果需要的话就使用ScriptManagerProxy。
  2. 当UserControl中放了ScriptManagerProxy的时候,引入自定义页面的那个页,就是用ScriptManager。
  • 那么我们如何判断页面中是否有ScriptManager呢。
Code
protected void btn_OnClick(object sender, EventArgs e)
{
ScriptManager x
= ScriptManager.GetCurrent(this);
if (x == null)
{
//no ScriptMangager
}
else
{
//do have
}
}

 

  • 这样,我们就可以通过以上的方法来判断其存在了。

抱歉!评论已关闭.