This article has been excerpted from book "The Complete Visual C# Programmer's Guide" from the Authors of C# Corner.
The Mobile Internet Toolkit is actually an extension of ASP.NET controls. When you install the toolkit, the installation program places the mobile DLL in the .NET Framework's directory and updates any necessary system files, and this provides you access to mobile controls with the .NET Framework. The Mobile Internet Toolkit consists of only one assembly, System.Web.Mobile.dll. The assembly contains two namespaces-System.Web.Mobile and System.Web.UI.MobileControls-for application development as well as a designer namespace.
When a mobile project is created with Visual Studio .NET, the setup program creates a virtual directory in IIS and stores the DLLs in the bin directory, so you can build mobile pages and run them through the server.
Mobile Web Forms Classes
Web forms in a wireless environment are called mobile Web forms. These forms are similar to Web forms but are designed to work with mobile devices. The mobile classes are similar to Web classes in ASP.NET. The Web Forms controls are described briefly in Table 24.1. We'll discuss these classes in more detail in the following sections.
Table 24.1: Mobile Web Controls
The MobilePage Control
The first class we will discuss is the System.Web.UI.MobileControls.MobilePage class. This class is inherited from the ASP.NET Page class. Below given example, is the starting point for using mobile controls in your page. Here we inherit our page from the MobilePage class.
Here is a simple scenario, where we inherit directly from the MobilePage class:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="cs" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
The language attribute must be set with the programming language you intend to use, such as C# or Visual Basic.
The Form Control
The Form control is another very basic control. As with any other type of Web application, a mobile form acts as a container for all other controls in the page. Any other control, whether it is a user interface, validation, or utility control, is contained within the <form> tag. So there must be at least one form in a mobile page.
Listing 24.2 is a simple example of using a form as a container. We discuss other user interface controls in detail in subsequent sections. In this example we display the text "Welcome to Mobile World" on the screen.
Listing 24.2: Welcome to Mobile World
<%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="CS" %>
<Mobile:Form id="Form1" runat="server">
<Mobile:Label id="Label1" runat="server">
WELCOME TO MOBILE WORLD
The code in Listing 24.2 simply displays a string on the mobile screen, as shown in Figure 24.2.
Figure 24.2: Displaying "Welcome to Mobile World"
Here we have used a Label control with the value WELCOME TO MOBILE WORLD. Before we deal with individual controls, let's discuss some of the basic properties that apply to most controls. They are as follows:
ID: Here you can specify an ID for almost all the controls and then reference the control using the ID attribute.
BackColor: Here you can specify the background color of a control. It is similar to the HTML BackColor attribute and can be set by the hexadecimal values specified for different colors.
FontSize: The size of the Font attribute can be set to Large, Small, Normal, or NotSet.
Visible: If the specified control is visible on the page, then the return value will be true. You can set the Visibility property for controls to true or false.
There is also a StyleSheet property, which allows you to define your own specific style. A custom style can be given a name and then referenced in your form, using the StyleReference property for that particular control.
Hope this article would have helped you in understanding the basics of the Mobile Internet Toolkit. See other articles on the website on .NET and C#.
| ||The Complete Visual C# Programmer's Guide covers most of the major components that make up C# and the .net environment. The book is geared toward the intermediate programmer, but contains enough material to satisfy the advanced developer.|