Building Microsoft ASP.NET Applications for Mobile Devices, Second Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Building Microsoft ASP.NET Applications for Mobile Devices, Second Edition [Electronic resources] - نسخه متنی

Andy Wigley; Peter Roxburgh

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
تنظیمات قلم


اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
افزودن یادداشت جدید

Creating Your First Mobile Web Applications

Visual Studio .NET is a complete development environment for authors of .NET Framework applications. Its graphical designer enables you to select mobile Web Forms controls from the Toolbox and then drag and drop them into position on mobile Web Forms. You can use any .NET-compliant language to code program logic, and the integrated editing and compilation facilities make producing accurate code much easier. Visual Studio .NET also features an integrated Web browser for testing, end-to-end debugging facilities, and powerful project file management, making it an indispensable tool for the mobile Web application developer.

Creating a Mobile Web Project with Visual Studio .NET

To create a project, you can click the Get Started option on the Start page and then click the New Project button. You can also create a project by clicking the File menu, pointing to New, and then clicking Project on the drop-down menu. The New Project dialog box appears, as shown in Figure 2-1.

Figure 2-1: The New Project dialog box

The left pane of the New Project dialog box allows you to select the project type. This pane offers one project type for each .NET language you've installed; the standard options are Microsoft Visual Basic, Visual C#, Visual J#, and Visual C++. Once you select your preferred language, the templates displayed in the right-hand pane change to reflect that language. All the languages offer similar options and allow you to create Web applications, as well as options to create other standard solutions such as Windows applications, class libraries, or Web services. Currently, Mobile Web Application templates are offered for the Visual Basic, Visual C#, and Visual J# languages.

It doesn't matter which language you choose for your first project, since the application won't require you to write code. Therefore, unless you have a preference, we suggest that you choose Visual C#. Click the ASP.NET Mobile Web Application option to highlight it, and then replace the suggested project name MobileWebApplication1 with the name MyFirstMobileApp. To do this, change the Location of the project from http://localhost/MobileWebApplication1 to http://localhost/MyFirstMobileApp. Visual Studio .NET updates the grayed out project name according to the location you enter.

Notice that below the Location text box Visual Studio .NET shows where it will create the project, in this case at the location http://localhost/MyFirstMobileApp of the Web server on your development machine. When you click OK, the Create New Web dialog box appears, informing you that Visual Studio .NET is creating the new Web application at http://localhost/MyFirstMobileApp.

Visual Studio .NET now updates its various dialog boxes with information relevant to your project. The default layout will look like Figure 2-2.

Figure 2-2: Mobile project development environment

The main view is a tabbed view, which displays all the files that you're currently working on, positioned one behind another. An asterisk next to the filename on the tab indicates that the file has been modified but hasn't been saved to disk yet.

Whenever you create a mobile Web application, the New Project Wizard creates your project with the name you specified and creates in it a number of files, including MobileWebForm1.aspx, which defines a mobile Web Forms page. This file is currently open and visible in the Mobile Internet Designer, which provides a GUI for designing mobile Web Forms.

Using Solution Explorer and the Properties Dialog Box

In Visual Studio .NET, on the upper-right side of your screen, you'll see Solution Explorer. This window lists all the files in your project. If you click the MobileWebForm1.aspx file listed there, the Properties dialog box on the lower-right side of your screen updates to reflect the properties of the currently selected object—that is, the MobileWebForm1.aspx file. This is a standard feature of Visual Studio .NET. Whenever you select an object, whether it's a user interface control you've dragged onto the design area of your mobile Web Forms, a file in Solution Explorer, or any other object listed on screen, the Properties dialog box updates so that you can easily change that object's properties.

Although not essential, it's a good idea to change the name of the mobile Web Forms file. When a browser accesses a Web application—mobile or otherwise—it does so by specifying that application's URL. The URL of the application you're creating is currently http://localhost/MyFirstMobileApp/MobileWebForm1.aspx.

You can also let users access the application by specifying the URL's shorter form, http://localhost/MyFirstMobileApp, thus enhancing the application's usability. To enable this functionality, you must change the name of the first file users will access to one of the standard default document names that IIS recognizes. The standard IIS default document names are Default, Default.asp, Iisstart.asp, or Default.aspx.

If IIS receives a request for a URL that doesn't specify a document, it will search the directory that stores Web site files for a file with a default document name. If IIS finds such a default document, it processes the document and returns the results to the caller; otherwise, it returns a Hypertext Transfer Protocol (HTTP) status code 404 (page not found). Giving your primary mobile Web Forms page one of the default document names makes it easier for users to remember the shorter name for your Web site; that way, they no longer have to include a nonintuitive document name such as MobileWebForm1.aspx within a request.

Click MobileWebForm1.aspx in Solution Explorer to select it. In the Properties pane, locate the File Name property and change it to default.aspx. Figure 2-3 shows the result.

Figure 2-3: Setting file properties


You could leave the name of your mobile Web Forms page as MobileWebForm1.aspx and configure IIS so that it recognizes that name as a default document. (Consult the IIS documentation for details on how to do this.) However, a better approach is to change the filename to one of the standard default document names; if you don't, the target Web server will require this additional configuration step when you deploy your application.

Building the User Interface with the Toolbox

The project that Visual Studio .NET created will build and run. Of course, the application currently does nothing. You'll now add a mobile control to the mobile Web Forms page so that your application displays a simple text message.

The Toolbox displays all the mobile Web Forms controls that you can use when designing your Web Forms. You can access the Toolbox by holding the mouse cursor over the Toolbox tab at the left margin of the screen. By default, this window is set to Auto Hide—it stays hidden until needed rather than taking up valuable screen space. If you right-click on the Toolbox when it is visible, you can set or clear the List View option. When set to List View, the controls are presented in a list showing their full name; when List View is disabled, only an icon is displayed for each control. As you move your mouse over each control, a ToolTip displays the control name. The Toolbox is divided into a number of tabs, each containing related controls, as shown in Figure 2-4.

Figure 2-4: The mobile Web Forms Toolbox

Select the compartment labeled Mobile Web Forms, which contains the standard mobile controls, such as the Label, TextBox, Command, and Image controls and the validation controls. You'll learn about these controls in more detail in Chapters 4 and 5.

An A icon denotes the Label control. You can click this control and drag it onto the mobile Web Forms page. Notice that the Properties window now shows the properties of the Label control, which has an ID value of Label1 and a Text property value of Label.

In the Properties window, change the Text property to something more meaningful, such as the venerable Hello World. Doing so updates the text displayed on the Label control shown in the Design view accordingly.

Building and Running Your Application

Visual Studio .NET offers many ways to build an application. Over time, you'll probably develop a preference or find yourself using certain methods at certain junctures. You can use one of the following methods to build your project:

Go to Solution Explorer, right-click the solution name, and click Build on the pop-up menu.

Right-click the MyFirstMobileApp project line immediately below the solution name, and then click Build Solution.

Click the Build menu, and then click Build.

Simply choose to run the application in Debug mode by clicking the Start button in Visual Studio .NET, which automatically initiates a build before running it.

The project will then compile, and you'll see the build output display at the bottom of the screen, including details of any compilation errors.

To test your application, you can click the Debug menu and then select Start or click the Start button on the standard toolbar. Internet Explorer starts and calls the IIS server to access your application, just as an external Web client would. Figure 2-5 shows MyFirstMobileApp running in Internet Explorer.

Figure 2-5: Testing the application with Internet Explorer

While Internet Explorer is active, Visual Studio .NET is running in Debug mode. Therefore, after you view the output from the application, close Internet Explorer to return Visual Studio .NET to Design mode.

/ 145