Master Pages and ASP.NET AJAX (C#)

In this lesson, you will learn how to include AJAX functionality in an entire web application using a master page. Only a ScriptManager control is needed on the master page and a ScriptManagerProxy control on the content page for the specific AJAX functionality.

Importance of AJAX

Over the past several years, more and more developers have been building AJAX-enabled web applications. An AJAX-enabled website uses a number of related web technologies to offer a more responsive user experience.

Creating AJAX-enabled ASP.NET applications is amazingly easy thanks to ASP.NET AJAX Framework.

ASP.NET AJAX is built into ASP.NET 3.5 and Visual Studio 2008. It is available as a separate download for ASP.NET 2.0 applications.

How to include AJAX

It is imperative to add one ScriptManager control to each and every page that uses the AJAX framework. The ScriptManager control manages the client-side script used in AJAX-enabled web pages.

The HTML instructs the browser to download the JavaScript files that make up the ASP.NET AJAX client library. After that, it can also be used to register user-specific (custom) JavaScript files, Script-enabled web services, and custom application service functionality.

The above requirement changes if you add a master page to the website. Then a ScriptManager control is added to only the master page.

Many of the larger ASP.NET applications today make use of master pages and power this technology. Master pages are providers for building template websites.

These days, ASP.NET includes ASP.NET AJAX as a part of the default install. You will find that master pages and AJAX go together quite well. The basic requirement for including AJAX capabilities is placing a ScriptManager Control on the page. For a particular design, place the single ScriptManager Control for the whole web application on the master page. This will make the page AJAX-enabled.

You can use this technique if your master page includes any AJAX capabilities, even if the content page makes no use of AJAX at all. This is also beneficial if you have JavaScript items to place on all pages of the web application.

If your content page also needs to make use of AJAX capabilities, you cannot simply add another ScriptManager control to the page. Instead, the content page needs to make use of the ScriptManager control already placed on the master page.

AJAX for content pages

If the content page needs specific functionality, it can access the controls on the master page using the ScriptManagerProxy server control. This ScriptManagerProxy control works exactly like this main ScriptManager control, except that it is meant for content pages making use of a master page. The ScriptManagerProxy control then interacts with the master page’s ScriptManager control to perform any necessary actions.

Get hands-on with 1200+ tech skills courses.