10. June 2008 22:00
ScriptManager sm = ScriptManager.GetCurrent(this);
Doing so gives you a reference to the Page's Script Manager and now you can change it's properties at run time. Do not forget to check for null (just in case).
So if that is the case then why shouldn't I include the Script Manager in the Master Page no matter whether I will use it or not. The reason why you shouldn't include it is because when you add the Script Manager ASP.NET adds a couple of references to some JS libraries. Those JS libraries are the ones that make ASP.NET Ajax work. By adding those JS libraries to the page you're also generating extra requests and also more data needs to travel through the pipe. So it really doesn't make sense to have the Script Manager in a page where you're not going to use it. It adds overhead.
So how about if I have an application where I use the Script Manager 90% of the time? I'm really adding unnecessary overhead to 10% of the pages. Well it's really not a matter of black and white and that's why I mentioned my answer is always "depends." Maybe those 10% pages equate to 70% of your traffic/bandwidth. In that case then you need to stop and think whether it's worth it or not and like almost every decision that we need to make in software development we have to measure the pros and cons.