Let's add a Web UI to your clock solution.

1 - Create the ASP.NET MVP Web Application Project

Create_WebViews_project.png

2 - Reference the existing Presenter Assembly

Open the Web.config file, and modify the Claymore config section like this :

<Claymore>
    <PresentersAssemblies>
      <!-- ADD YOUR ASSEMBLIES HERE -->
      <Add assemblyName="Clock.Presenters"/>
    </PresentersAssemblies>
  </Claymore>

Note : At runtime Claymore will dynamically invoke the Presenters implementation; So that Clock.Presenters.dll must be placed in the output directory (bin/debug or bin ) of the project.

3 - Design the ASP.NET UI

Open Default.aspx file and follow this example :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Clock.WebViews.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="BtnTime" runat="server" Text="What time is it?"/>
        <asp:Label ID="LblWord" runat="server"></asp:Label>
    </form>
</body>
</html>

4 - Implement the View

Open Default.aspx.cs and add the following code :

using System;
using System.Web.UI;
// include your IView namespace(s) here.
using Clock.IViews;

namespace Clock.WebViews
{
    /// <summary>
    /// Add your IViews Implementations here.
    /// </summary>
    public partial class Default : Page, IClockView
    {
        public event GetTimeEventHandler GetTime;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            BtnTime.Click += onGetTimeClicked;
        }

        private void onGetTimeClicked(object sender, EventArgs e)
        {
            if (GetTime != null)
                LblWord.Text = GetTime(this, EventArgs.Empty);
        }
    }
}

5 - Launch it :)

WebViews_Run.png

Last edited Feb 17, 2010 at 9:22 PM by Fab_Michellonet, version 3

Comments

No comments yet.