Export (0) Print
Expand All

How to: Add a 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 Page (with presenter) Recipe to generate a page with presenter.

Prerequisites

The Add 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 page class. This means you can only use the recipe to add 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 page to a module with a name that is not a valid identifier, the generated code will not compile.

Ff709891.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 page with presenter.

To use the Add Page (with presenter) recipe to create a 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 Page (with presenter) (C#) or Add Page (with presenter) (Visual Basic), as shown in Figure 1.

    Ff709891.16556a80-4916-413b-a62d-dad17c59d7e4(en-us,PandP.10).png

    Figure 15

    The Add Page (with presenter) recipe menu
    Ff709891.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 Page (with presenter) Wizard, as illustrated in Figure 2.

    Ff709891.bee4b49d-cb0b-41df-9908-e5cd09a332d2(en-us,PandP.10).png

    Figure 16

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

Outcome

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

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

    Ff709891.abdd657c-3b18-49e2-8593-5ec731ea07e2(en-us,PandP.10).png

    Figure 17

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

Next Steps

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

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