Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ASP .NET 2.0 Beta Preview - B. Evjen.pdf
Скачиваний:
26
Добавлен:
24.05.2014
Размер:
15.33 Mб
Скачать

Chapter 6

You can find a list of available browsers on the production server where the application will be hosted at

C:\WINDOWS\Microsoft.NET\Framework\v2.0.xxxxx\CONFIG\Browsers. Please note that your version number may vary. Some of the available options include

 

avantgo

 

mozilla

 

cassio

 

netscape

 

default

 

nokia

 

docomo

 

openwave

 

ericsson

 

opera

 

gateway

 

palm

 

generic

 

panasonic

 

goAmerica

 

pie

 

ie

 

webtv

 

jphone

 

xiino

MME

Of course, you can also add any additional .browser files that you deem necessary.

Event Ordering

When you work with master pages and content pages, both can use the same events (such as Page_Load). Be sure you know which events come before others. You are bringing two classes together to create a single page class, and a specific order is required. When an end user requests a content page in the browser, the event ordering is the following:

Master page child controls initialization: All server controls contained within the master page are first initialized.

Content page child controls initialization: All server controls contained in the content page are initialized.

Master page initialization: The master page itself is initialized.

Content page initialization: The content page is initialized.

Content page load: The content page is loaded (this is the Page_Load event followed by the

Page_LoadComplete event).

Master page load: The master page is loaded (this is also the Page_Load event followed by the

Page_LoadComplete event).

Master page child controls load: The server controls on the master page are loaded onto the page.

Content page child controls load: The server controls on the content page are loaded onto the page.

200

Working with Master Pages

Pay attention to this event ordering when building your applications. If you want to use server control values that are contained on the master page within a specific content page, for example, you can’t retrieve the values of these server controls from within the content page’s Page_Load event. This is because this event is triggered before the master page’s Page_Load event. This problem prompted the creation of the new Page_LoadComplete event. The content page’s Page_LoadCompete event follows the master page’s Page_Load event. You can, therefore, use this ordering to get at values from the master page even though it isn’t populated when the content page’s Page_Load event is triggered.

Caching with Master Pages

When working with typical .aspx pages, you can apply output caching to the page by using the following construct (or variation thereof):

<%@ OutputCache Duration=”10” Varybyparam=”None” %>

This caches the page in the server’s memory for 10 seconds. Many developers use output caching to increase the performance of their ASP.NET pages. It also makes a lot of sense for use on pages with data that doesn’t become stale too quickly.

How do you go about applying output caching to ASP.NET pages when working with master pages? First, you cannot apply caching to just the master page. You cannot put the OutputCache directive on the master page itself. If you do so, on the page’s second retrieval, you get an error because the application cannot find the cached page.

To work with output caching when using a master page, stick the OutputCache directive in the content page. This caches both the contents of the content page as well as the contents of the master page (remember, it is just a single page at this point). The OutputCache directive placed in the master page does not cause the master page to produce an error, but it won’t get cached. This directive only works in the content page.

Summar y

When you create applications that use a common header, footer, or navigation section on pretty much every page of the application, master pages are a great solution. Master pages are easy to implement and enable you to make changes to each and every page of your application by changing a single file. Imagine how much easier this makes managing large applications that contain thousands of pages.

This chapter described master pages in ASP.NET 2.0 and explained how you build and use master pages within your Web applications. In addition to the basics, the chapter covered master page event ordering, caching, and specific master pages for specific containers. In the end, when you are working with templated applications, master pages should be your first option — the power of this approach is immense.

201