Daniel
Daniel

Reputation: 91

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

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?

Upvotes: 2

Views: 588

Answers (2)

Cos Callis
Cos Callis

Reputation: 5084

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

Upvotes: 1

acconrad
acconrad

Reputation: 3219

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.

Upvotes: 3

Related Questions