如何确定页面上是否需要 Asp.net Scriptmanager
有没有一种简单的方法来确定页面上是否有需要脚本管理器的控件?我在页面初始化中向每个页面添加一个脚本管理器(效果很好),但似乎有一个比强制每个页面都有脚本管理器更好的方法。也许四分之一的页面有更新面板或某种扩展程序。或者这并不算什么额外的负担,只是不用担心?
Is there a simple way to determine if there is a control on a page that requires a scriptmanager? I am adding a scriptmanager to every page (which works great) in my page init, but it seems like there would be a better way than just forcing every page to have a scriptmanager. Maybe 1 in 4 pages have update panels, or some sort of extender. Or is it not much of an extra load and just not worry about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
利用继承来发挥自己的优势。创建某种
ScriptManagerPageBase
类,其PageInit
方法调用新的ScriptManager
。对于需要ScriptManager
的每个页面(例如使用UpdatePanel
控件),只需让该页面从ScriptManagerPageBase
继承,您就只能获得该功能当您需要时,无需重复代码。Use inheritance to your advantage. Create some sort of
ScriptManagerPageBase
class whosePageInit
method invokes a newScriptManager
. For every page that requires yourScriptManager
, such as usingUpdatePanel
control, simply have that page inherit fromScriptManagerPageBase
and you'll get that functionality only when you need it, without having to duplicate code.在您的母版页(或基页,具体取决于您的方法,我建议母版页..)中,只需添加一个脚本管理器。除非需要,否则它不会影响运行时的页面。然后向每个需要 scriptmanager 的页面或控件添加 scriptmanagerproxy。在运行时,代理将找到基本或主管理器并注册任何以前未注册的脚本。请参阅 MSDN SCRIPTMANAGERPROXY 说明
In your master page (or a base page depending on your approach, I recommend master pages..) just add a scriptmanager. Unless needed it will not affect the page at runtime. Then add a scriptmanagerproxy to each page or control that needs a scriptmanager. At runtime the proxy will find the base or master manager and register any previously unregistered scripts. See MSDN SCRIPTMANAGERPROXY discription