10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9<br />

❑<br />

❑<br />

❑<br />

The use of an httpHandler or httpModule is similar in the respect that <strong>ASP</strong>.<strong>NET</strong> will process<br />

the requests through either the handler or module before allowing the page to execute. To<br />

signify this distinction, from now on we will refer to the use of either an httpHandler or<br />

httpModule as “preprocessing.” Preprocessing provides a layer where the application will<br />

examine requests coming to the server to determine if any <strong>Ajax</strong> support is required to render<br />

to the page. Preprocessing configuration options are not enough alone to grant a page <strong>Ajax</strong> support,<br />

but less work is required on a page level.<br />

Some frameworks have a base page class that you inherit your <strong>ASP</strong>.<strong>NET</strong> web forms from instead<br />

of the traditional System.Web.UI.Page class. The custom base class will encapsulate the required<br />

plumbing that your page needs to handle <strong>Ajax</strong> interaction between the client and server.<br />

The final option is to use a page control directive. These directives allow you to declaratively<br />

add <strong>Ajax</strong> support to a page at design time. The page control directive can supersede the need<br />

for preprocessing or the use of a base page class.<br />

You will see each of these options implemented in coming examples.<br />

Benefits<br />

Preprocessing allows each page in your application the ability to cycle through your <strong>Ajax</strong> engine. This<br />

can make turning on <strong>Ajax</strong> features of a page easier because there is less code you must write on the<br />

page level.<br />

Base classes give you all the benefits of inheritance by giving your page <strong>Ajax</strong> processing support “for free.”<br />

The base class will often include useful services that make coding easier, but the true benefit is found in ease<br />

of use. Often frameworks that provide a base class require very little extra coding to create an <strong>Ajax</strong> experience.<br />

Another benefit to using a base class lies in the fact that you may inherit from the class. This extra layer<br />

of abstraction allows you to make changes and provide services to your <strong>Ajax</strong> pages in one place.<br />

Page control directives perhaps give you the best of both worlds, because you will avoid the disadvantages<br />

(stated in the following section) of the preprocessing and base class options, while still giving your<br />

page full <strong>Ajax</strong> support.<br />

Drawbacks<br />

In some experiments with frameworks that use preprocessing, we have found a few cases where the <strong>Ajax</strong><br />

httpHandler or httpModule interfered with applications that used their own custom handler or module.<br />

The preprocessing configuration may not be the best option for you if you are working on a project<br />

that already employs its own handlers or modules. Test rigorously to ensure a true working solution.<br />

The drawbacks to base classes are classic in object-oriented development. If want to use a solution that<br />

requires you inherit from the base class, you may run into a few problems. What if you are already inheriting<br />

from your own base class? The .<strong>NET</strong> runtime does not support multiple inheritances, so you must<br />

then make a choice; do you keep your base class or go with the base class from the third-party framework?<br />

Other questions you might pose to yourself are: What if I change <strong>Ajax</strong> libraries? What will that<br />

to do my inheritance structure? Although base classes at first may seem attractive, implementation by<br />

inheritance, rather than composition may often architecturally limit you in the end.<br />

Page control directives are nice because they are a light-touch addition to your page. However, since you<br />

are not inheriting from the control, making global changes becomes more difficult. If you wanted to add<br />

206

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!