开发者

How do you determine if a Asp.net Scriptmanager is necessary on a page

开发者 https://www.devze.com 2023-02-28 04:53 出处:网络
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中文

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

0

精彩评论

暂无评论...
验证码 换一张
取 消