Inside ASP.NETby Scott Worley, Ken Cox, Budi Kurniawan
Inside ASP.NET provides experienced software and web developers with accurate and concise information on the technologies and concepts introduced in Microsoft's new and revolutionary development platform, ASP.NET. Covering topics such as ADO.NET, Web Services, cache control, globalization, and Mobile Device Development, Inside ASP.NET offers the most/i>… See more details below
Inside ASP.NET provides experienced software and web developers with accurate and concise information on the technologies and concepts introduced in Microsoft's new and revolutionary development platform, ASP.NET. Covering topics such as ADO.NET, Web Services, cache control, globalization, and Mobile Device Development, Inside ASP.NET offers the most comprehensive overview of ASP.NET available.
Written for the experienced user, this book is the only one you will need to transition your skill set from ASP to ASP.NET.Author Scott Worley supplies you with many source code examples individually relating to every concept introduced within this book. In addition, Worley also provides a full ASP.NET-based online task management application used as the final case-study project in this book.
Read an Excerpt
16: Mobile Device Development with ASP.NETMobile devices are becoming increasingly popular. Over the past few years, mobile phones have become so common that it is more of a rar-ity to see someone without one. Personal Digital Assistants (PDAs), such as Palm Pilots, also are popular. Combine this with the fact that the Internet is everywhere. It goes without saying that tremendous opportunity exists for the savvy web developer to take advantage of this current state of accessibility.
So, how can a developer take advantage of this? Consider the following: Most people use the Internet as a means of finding information. Ironically, it is not always possible to get to an Internet PC or Mac; however, most people have more convenient access to a mobile phone or PDA.This means that there is an enormous, untapped market for mobile Internet services. After all, imagine being able to use your mobile device not only for sending and receiving your email, but also for receiving information from the sports and news feeds or the company you work for, or being able to book and purchase tickets through online services.The possibilities are limitless!
This chapter introduces the mobile device types you can develop, and provides a brief overview of the underlying technology used for writing applications for mobile devices:
- Covering Wireless Application Protocol (WAP)
- Wireless Markup Language (WML)
- WMLScript (the script language for WML)
Software You Need for This Chapter
To use the examples in this chapter, your development machine has to have the following software installed as well as ASP.NET:
- Mobile Internet Toolkit�This can be downloaded from http://www.asp.netwww.asp.net .
- A WAP-enabled Microbrowser or emulator�this book uses Openwave UP Simulator 4.1. For the examples in this book, you can download this emulator from http://www.phone.com .
Wireless Application Protocol (WAP)The WAP architecture is not that different from the WWW architecture. In fact, the WAP architecture is based on the existing WWW architecture, which means if you understand the WWW architecture, you can understand the WAP architecture.
Most of the technology developed for the Internet has been designed with the desktop user in mind, which in itself presents some rather interesting issues when developing Mobile Internet Device applications. For instance, a desktop user has a large display with which to view, a keyboard for data entry, and a fast Internet connection. Compare this to the mobile device user who has a limited display area and limited data entry ability. The WAP architecture, although based on existing web technology, has numerous optimizations for wireless data transfer. Most of these optimizations deal with the fact that the wireless data communications technology available to the public has a small bandwidth capacity. In most cases, the bandwidth capacity is less than 15Kbps, which is considerably less when compared to conventional web browsing technology, which runs at an average minimum of 56Kbps.
When a mobile device user requests a web page, the following request and response process occurs:
- The user requests a URL from his Microbrowser.
- . The WAP browser encodes the request into WML format and then sends the request to a WAP gateway.
- The WAP gateway receives the WAP request, converts the WAP request into an HTTP request, and then sends it to a web server.
- The web server receives the HTTP request, performs whatever processing is required, and then sends back an HTTP response to the WAP gateway.
- The WAP gateway receives the HTTP response, converts the HTTP response into a WAP response, and then sends it to the WAP device that requested it.
- The WAP Microbrowser software receives a WAP response and renders it to the mobile device display.
The WAP Forum is an association that developed the WAP standard. It is made up of more than 500 members worldwide. It has the sole objective of promoting the WAP standard and assisting companies in the adoption of the standard.
For more detailed information on the WAP architecture, go to the WAP Forum web site at www.wapforum.org .
Wireless Markup Language (WML) The WAP architecture also includes a markup language that is similar to HTML in structure; this is called WML. This markup language is used to render information back to the user of a mobile device through a Microbrowser.
WML is not an overly complex language, and it benefits from being based on HTML; however, the similarity is only in the structure of the syntax. In Listing 16.1, you can see a simple WML application.
In line 4, you can see the <wml>element.This element outlines what is referred to as a deck, a collection of cards and forms for a mobile device application. In line 5, we encounter the first <card>element. A <card>element is used like a page. It contains all the rendering commands for a single screen of data on a mobile device. The WML file can have more than one card nested inside the <wml>elements. After the card definition, we use a <p> tag to surround any content we need to display. The <p>is not optional�it has to be used or the mobile device will not render any of the content for the card. Line 7 contains text to display on the device.
Figure 16.1 shows the screen after the mobile device receives the WML file.
Enter ASP.NETSo, now you have had a brief look at WAP and WML. It's time to see how this all relates to the Mobile Device SDK for ASP.NET. Table 16.1 outlines some key elements used in WAP/WML development and explains the equivalent elements in ASP.NET...
You can use <wml>elements inside ASP.NET mobile forms without any problems. However, it is better to use ASP.NET controls because the mobile control's toolkit can generate either WML or HTML depending on the capa-bilities of the device to which it is rendering.
Creating a Mobile Device ApplicationASP.NET Mobile controls are defined as elements in exactly the same man-ner as regular ASP.NET controls.The only thing you have to do with Mobile controls is make sure that at the top of your web page, you register the Mobile Internet Toolkit controls and namespace as shown:
01 <%@Page Inherits="System.Web.UI.MobileControls.MobilePage " Language=="vb " %%> 02 <%@Register TagPre .x="mobile " Namespace=="System.Web.UI.MobileControls " 03 Assembly="System.Web.Mobile " %%>
On the first line, the Web Form properties are inherited from the System.Web.UI.MobileControls.MobilePage class. This class provides the core functionality of a mobile device web page. Also, the language is set for any script on the web page to use Visual Basic .NET. The second line registers the TagPre .x to mobile for the namespace System.Web.Mobile.UI.MobileControls . This enables access to a Mobile control without having to type in the long namespace first. For more on this, see Chapter 2,"Developing Applications with ASP.NET."
After this has been done, you are ready to start using the Mobile Internet Toolkit controls to build your application.
The Form ElementThe Form element is required for every single mobile device web page without exception.You can have more than one form to a Web Form source file; however, only one form at a time will be rendered on the mobile device. The first form definition in your source file is the initial form that will be displayed on the mobile device. The syntax for the form control follows:
01 Mobile:Form runat=server 02 id="id-of-control " 03 StyleReference="StyleReference " 04 OnActivate="OnActivateHandler " 05 OnDeactivate="OnDeactivateHandler ">
The id attribute is used to create a unique identifier for the Form in the source file. This is important because you can have many forms in a file, and you will need to reference each form for navigational purposes if nothing else. The StyleReference attribute is used to apply a style sheet to any controls inside the Form elements. More on this attribute in the "Presentation Controls" section later in this chapter. The OnActivate and OnDeactivate attributes are used to call a function after these events happen.The OnActivate event occurs when the form is first displayed, and the OnDeactivate event occurs when the form is replaced by another form.
An example of the Form control with an OnActivate event handler is defined in Listing 16.2....
and post it to your social network
Most Helpful Customer Reviews
See all customer reviews >