Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

764 Project 6 CREATING A MOBILE APPLICATION

In the preceding chapters, you looked at the case study and design of the MobileCallStatus application. In addition, you were introduced to the basics of a mobile Web application. Based on this learning, you created a simple mobile Web application in the .NET Framework. In this chapter, you will create the forms required for the MobileCallStatus application.You will also add the business logic

to the MobileCallStatus application.

Creating the Forms Required for the MobileCallStatus Application

You have already seen the design of the forms required for the MobileCallStatus application. In this chapter, I will discuss how to create the mobile Web forms for the MobileCallStatus application.

Before creating the mobile Web forms, you need to create a mobile application with the name MobileCallStatus. To create a mobile application with the name MobileCallStatus, perform the following steps:

1.On the File menu, point to the New option.

2.In the displayed list, click on the Project option. The New Project dialog box is displayed.

3.In the Project Types: pane of the New Project dialog box, select the Visual C# option.

4.In the Templates: pane, select the Mobile Web Application option.

5.In the Location: text box, the local host appears by default. Type the name of the application as MobileCallStatus.

6.Click on the OK button.

Figure 33-1 shows the IDE (Interactive Development Environment) for the MobileCallStatus application.

IMPLEMENTING THE BUSINESS LOGIC

Chapter 33

765

 

 

 

 

FIGURE 33-1 The IDE for the MobileCallStatus application

As you can see in Figure 33-1, Visual Studio .NET automatically creates the default files. In addition, Visual Studio .NET generates default code.The following section discusses the default code generated by Visual Studio .NET for a mobile application.

The Default Code Generated by Visual Studio

.NET for a Mobile Application

The default code generated by Visual Studio .NET is as follows:

using System;

using System.Collections; using System.ComponentModel; using System.Data;

using System.Drawing; using System.Web;

using System.Web.Mobile;

766 Project 6 CREATING A MOBILE APPLICATION

using System.Web.SessionState; using System.Web.UI;

using System.Web.UI.MobileControls; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;

namespace MobileCallStatus

{

public class MobileWebForm1 : System.Web.UI.MobileControls.MobilePage

{

protected System.Web.UI.MobileControls.Form Form1; private void Page_Load(object sender, System.EventArgs e)

{

}

}

}

The preceding code contains the using directive statements that allow you to use the namespace and the classes defined in the namespace within the code for your application. In addition, the Visual Studio .NET creates a namespace with the same name as that of the application, MobileCallStatus.

Inside the MobileCallStatus namespace, a public class with the name MobileWebForm1 is created. The MobileWebForm1 class is derived from the MobilePage class that lies in the System namespace. The MobileWebForm1 class contains the declaration of the instance of the Form class, Form1. In addition, the MobileWebForm1 class contains the Page_Load() method. You can include the statements required for initializing the mobile page in the Page_Load() method.

In addition to the preceding code, Visual Studio .NET creates HTML code for the mobile application. To view the HTML code, switch to the HTML page in the IDE. To do this, select the HTML Source option on the View menu. Figure 33-2 shows the HTML code for the MobileCallStatus application.

IMPLEMENTING THE BUSINESS LOGIC

Chapter 33

767

 

 

 

 

FIGURE 33-2 The HTML code for the MobileCallStatus application

As you can see in Figure 33-2, the first two lines of the HTML code are highlighted.These two lines are called the prolog for the MobileCallStatus application. The @ Page directive includes the information about the mobile page.This information includes the language used for developing the mobile application, the mobile Web form included in the mobile page, and the base class of the mobile Web page. The @ Register directive includes the information about the namespace and the assembly for the mobile Web page.

Next, the HTML code includes the meta information for the HTML code, such as the software and the language used to create the mobile application. In addition, the meta statements include the information about the schema used for creating the mobile Web page. Next, the HTML code contains the body tags. Inside the body tags, the information about the mobile Web form is included.

After discussing the code generated by Visual Studio .NET, I will continue discussing how to create forms for the MobileCallStatus application.

Creating the frmLogon Form

You have seen the design of the frmLogon form. You can now create the frmLogon form. To create the frmLogon form, drag two Label controls, two TextBox

768 Project 6 CREATING A MOBILE APPLICATION

controls, two RequiredFieldValidator controls, and one Command control to the form. Next, change the following properties of the controls:

Label1

ID: Label1

 

 

 

Text: Please Log On

Y

Font:

 

 

 

Bold: True

 

 

 

 

 

 

L

Label2

 

 

 

M

 

ID: lblMessage

A

 

 

F

 

Visible: False

E

 

 

 

Font:

T

 

 

 

 

Bold: True

TextBox1

ID: TextBox1

TextBox2

ID: TextBox2

Password: True

RequiredFieldValidator1

ID: RequiredFieldValidator1

ControlToValidate: TextBox1

ErrorMessage: Please provide a valid logon name

Team-Fly®