How to: Add a Master Page with a Presenter
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
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.
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.
|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.|
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
- 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.
Note: 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.
- In the Master Page name box, type the name for the master page.
- Select the module. The recipe will create the presenter class and master page interface in this project.
- Click Finish. The recipe generates the master page with presenter.
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
|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.|
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.