Listing 1: The custom label control class
using System;
using System.Web.UI.MobileControls;
namespace CustomLabel
{
/// <summary>
/// Simple Custom Mobile Control
/// </summary>
///
public class CLabel : MobileControl
{
private string pname, room, status;
public CLabel()
{
Pname="";
Room="";
Status="";
}
public string Pname
{
get
{
return pname;
}
set
{
pname = value;
}
}
public string Room
{
get
{
return room;
}
set
{
room=value;
}
}
public string Status
{
get
{
return status;
}
set
{
status=value;
}
}
}
}
Listing 2: The HTML adapter class
using System;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using CustomLabel;
namespace CustomLabel.Adapters
{
/// <summary>
/// HTML Adapter for Custom Control
/// </summary>
public class CLHTMLAdapter: HtmlControlAdapter
{
protected new CLabel Control
{
get
{
return(CLabel)base.Control;
}
}
public override void Render(HtmlMobileTextWriter
writer)
{
writer.EnterStyle(Style);
writer.WriteLine("Patient: " + Control.Pname + "</p>");
writer.WriteLine("<p> Room: " + Control.Room + "</p>");
writer.WriteLine("<p> Status: " +
Control.Status);
writer.ExitStyle(Style);
}
}
}
Listing 3: The WML Adapter Class
using System;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using CustomLabel;
namespace CustomLabel.Adapters
{
/// <summary>
/// WML Adapter for Custom Control
/// </summary>
public class CLWMLAdapter: WmlControlAdapter
{
protected new CLabel Control
{
get
{
return(CLabel)base.Control;
}
}
public override void Render(WmlMobileTextWriter
writer)
{
writer.EnterStyle(Style);
writer.RenderText("Patient: " + Control.Pname);
writer.WriteLine("</p>");
writer.Write("<p>");
writer.RenderText("Room: " + Control.Room);
writer.WriteLine("</p>");
writer.Write("<p>");
writer.RenderText("Status: " + Control.Status);
writer.ExitStyle(Style);
}
}
}
Listing 4: Edited WebForm.aspx
<%@ Register TagPrefix="CustomLabel" Namespace="CustomLabel"
Assembly="CustomLabel" %>
<%@ Page language="c#" Codebehind="MobileWebForm1.aspx.cs"
Inherits="MobileWebApplication2.MobileWebForm1" AutoEventWireup="false" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" %>
<meta name="GENERATOR" content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" content="C#">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/Mobile/Page">
<body Xmlns:mobile="http://schemas.microsoft.com
/Mobile/WebForm">
<mobile:Form id="Form1" runat="server">
<CustomLabel:CLabel id="CLabel1" runat="server"
Status="Stable" Room="23" Pname="John
Doe"></CustomLabel:CLabel>
</mobile:Form>
</body>