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, 开发者_StackOverflow中文版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?
Use inheritance to your advantage. Create some sort of ScriptManagerPageBase
class whose PageInit
method invokes a new ScriptManager
. For every page that requires your ScriptManager
, such as using UpdatePanel
control, simply have that page inherit from ScriptManagerPageBase
and you'll get that functionality only when you need it, without having to duplicate code.
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
精彩评论