One caveat to using the ScriptManager on your pages is that you can only have one ScriptManager reference at a time. What if you are writing a content page for a master page that has a ScriptManager on it; but you need to now make sure that the ScriptManager references a particular service your content page needs - what do you do? You could check out the MaterPage and make the necessary modifications - but why? That's actually not a very good idea because it kind of breaks the whole concept of master/content page seperation; especially in scenarios where a certain developer can't or shouldn't have access to the master page (say you're farming a particular content page out to a consultant, etc).
The answer when you need to reference a service from your content page and yet the ScriptManager resides on the MasterPage is a ScriptManagerProxy. The ScriptManagerProxy works by detecting the main (real) ScriptManager on your page at runtime and hooking itself to that ScriptManager, making sure that any references given to it are also given to the real ScriptManager. In fact, it's constructor takes a real ScriptManager as a parameter:
internal ScriptManagerProxy(IScriptManagerInternal scriptManager) { this._scriptManager = scriptManager; }
protected override void OnInit(EventArgs e) { base.OnInit(e); if (!base.DesignMode) { this.ScriptManager.RegisterProxy(this); } }
if (this._proxies != null) { foreach (ScriptManagerProxy proxy in this._proxies) { proxy.RegisterServices(this); } }
Remember Me
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.