Using a User Control in a Web Forms Page
Working with a user control in an application is quite simple. You place the .ascx file and its code-behind file (if one exists) in the application directory or another accessible directory. Then you declare the TagPrefix and TagName that you'll use to represent the user control within the page, as well as the path to the file containing the user control source. You place the TagPrefix and TagName declarations at the head of the mobile Web Forms page, alongside the usual declarative statements. Here's the syntax:<%@ Page language="c#" Codebehind="MobileWebForm1.aspx.cs"
Inherits="MSPress.MobWeb.UserControlExample.MobileWebForm1"
AutoEventWireup="false" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<%@ Register TagPrefix="custom"
TagName="ShortDateUC"
Src="ShortDateControl.ascx" %>
Next you employ the user control in the same way as you would a standard mobile control, but you use the declared TagPrefix and TagName:
<mobile:Form id="Form1" runat="server">
<custom:ShortDateUC runat="server" id="ucShortDate" />
</mobile:Form>
When you dragged the user control onto the Form control, as described in the section "Creating a Simple User Control," earlier in this chapter, Visual Studio .NET inserted this syntax into the mobile Web Forms page.