Export (0) Print
Expand All

How to: Add a Master Page with a Presenter

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

You can use the Model-View-Presenter pattern to separate the responsibilities for the visual display and the event handling behavior into different classes. Separation of these concerns leads to simplified classes, allows reuse of presentation logic, and helps you test the presentation logic without a visual user interface.

This topic describes how to use the Add Master Page (with presenter) Recipe to generate a master page with presenter.

Prerequisites

The Add Master Page (with presenter) recipe assumes that you have an existing Web client solution. For information about how to create a Web client solution, see How to: Create a Web Client Solution.

The recipe applies to a Web site root node or to a folder in a Web site that contains a Web.config file (typically, this is a Web folder for a business module).

The recipe uses the module name as a prefix for the generated master page class. This means you can only use the recipe to add master pages to modules that have names that are valid identifiers (for example, the module name does not include a period, such as Reports.Module). If you use the recipe to add a master page to a module with a name that is not a valid identifier, the generated code will not compile.

Ff709842.note(en-us,PandP.10).gifNote:
The Add Business Module recipe requires you to use a valid identifier for the module name. If you rename a business module after you create it, select a name that is a valid identifier.

Steps

The following procedure describes how to use the recipe to create a master page with presenter.

To use the Add Master Page (with presenter) recipe to create a master page with presenter

  1. In Solution Explorer, right-click a Web site or a folder in a Web site, point to Web Client Factory, and then click Add Master Page (with presenter) (C#) or Add Master Page (with presenter) (Visual Basic), as shown in Figure 1.

    Ff709842.c5baba69-4479-4a28-8373-e5c12327e218(en-us,PandP.10).png

    Figure 18

    The Add Master Page (with presenter) recipe menu
    Ff709842.note(en-us,PandP.10).gifNote:
    If you are running the recipe in a Web Application project, you will see only the recipe menu items corresponding to the project’s language.

    The recipe starts the Add Master Page (with presenter) wizard, as illustrated in Figure 2.

    Ff709842.3e3e5649-56d7-4d43-af5f-fe393cd3b24f(en-us,PandP.10).png

    Figure 19

    The Add Master Page (with presenter) recipe wizard
  2. In the Master Page name box, type the name for the master page.
  3. Select the module. The recipe will create the presenter class and master page interface in this project.
  4. Click Finish. The recipe generates the master page with presenter.

Outcome

You will have the following elements in your solution, as shown in Figure 3:

  • A master page interface definition in the MasterPages folder of the module project
  • A presenter class in the MasterPages folder of the module project
  • A master page implementation in the module's Web site folder

Ff709842.17b78370-deeb-4f57-829d-15832319a6df(en-us,PandP.10).png

Figure 20

Solution with the master page View1 in the business module Module1
Ff709842.note(en-us,PandP.10).gifNote:
If you have a test project for the business module that contains the new master page, the recipe will create a test fixture class for the presenter in the MasterPages folder of the test project.

Next Steps

The following are typical tasks that you perform after you create a master page with presenter:

  • Design the UI of your master page. Define styles and the layout of the master page.
  • Implement your master page. Add controls to the master page and forward user events to the presenter.
  • Define the master page interface. The master page should expose its state through its public interface. Typically, master page interfaces have properties such as Customers or SelectedAccount.
  • Create unit tests and implement the presenter. Handle user events and update the master page state. Interact with the module controller to execute business and navigation logic.
  • Create views. Create new views that consume your master page or update existing views to consume the master page.
  • Add user controls. Add new user controls to your module.
Show:
© 2014 Microsoft