Basics of ASP. NET mobile development (1)

Source: Internet
Author: User

With the rapid development of hardware, mobile devices have shown better performance, faster processing speed, and cheaper trends like computer devices. In particular, the coming 3G technology will allow mobile devices to break through the current bandwidth limit, so that we can build many novel and powerful mobile applications. Many commercial applications have begun to migrate to mobile devices. Therefore, it is a very suitable time for developers to start learning ASP. NET mobile development.

Of course, I can't discuss all the detailed processes of using ASP. NET mobile development applications in this example. This article will introduce some basic knowledge, so that you have a general understanding of using ASP. NET 2.0 technology to develop mobile applications, so that you can quickly go deep into this technology. First, we will learn how to create an ASP using Visual Studio 2005. NET 2.0 mobile app, then introduce some common mobile development controls and add them to the app in a suitable way, finally, you will learn how to develop ViewState and Session in WEB programs and management programs for specific mobile devices.

Create a new ASP. NET mobile WEB program

Visual Studio 2005 provides a set of powerful and friendly development tools to create mobile WEB programs. If you have already created traditional ASP. NET application experience, you will find that creating mobile WEB programs and creating traditional ASP. NET applications are very similar. You only need to create an ASP. NET Website project and add some mobile WEB forms. After you add a mobile WEB form, you will find that the ASP. NET mobile control is added to the toolbox, as shown in.

Now you can follow the steps below to create a new WEB program for ASP. NET mobile development in Visual Studio 2005:

1. Select "file"-"New"-"website"

2. In the "templates installed in Visual Studio" list, select "ASP. NET Website"

3. After setting options such as "location", "language", and "path" of the program, click "OK.

After completing the preceding steps, you have created an ASP. NET Website. Now we can add some WEB forms for mobile devices to the website. The specific implementation process is as follows:

1. In the "Solution Explorer" Window of Visual Studio 2005, right-click the website project you just created and choose "Add new project" from the shortcut menu.

2. In the pop-up "Add new item" form, select "mobile WEB form.

3. Set the "name" and "language" of the form, and make sure that the "put code in a separate file" selection box is selected.

4. Click "add.

After you click the "add" button, you will find that Visual Studio 2005 automatically adds two files. Here, the form name is set to "MobileDefault", so the two files are respectively MobileDefault. aspx and MobileDefault. aspx. cs (if you select VB, the two files are MobileDefault. aspx and MobileDefault. aspx. vb ). MobileDefault. the aspx file contains various ASP. NET mobile controls, while MobileDefault. aspx. cs contains some program implementation code and event processing code, which is similar to the traditional ASP.. NET Applications adopt the same "post-code" method.

After the form is added, you can use the controls under the "mobile WEB Forms" label in the toolbox. Like other ASP. NET controls, we can also set the properties and event behavior of these controls as needed. In the "original code" window, you can directly enter the "mobile:/" syntax to add a mobile control:

 
 
  1. <Mobile: TextBox ID ="MyTextBox"Runat ="Server"> 〉
  2. </Mobile: TextBox> 〉
  3. <Mobile: Label ID ="MyLabel"Runat ="Server"> 〉
  4. Label Control </mobile: Label> 〉

Displays a mobile WEB form with the Label, TextBox, and Command controls. The function implemented by the form is to search for the corresponding user information based on the CustomerID entered in the TextBox Control. We did not write the corresponding logic code, but only showed the interface of the form:

The HTML code in Visual Studio 2005 is as follows. We can see that the preceding three controls are declared in the page code with the prefix "mobile. Similarly, Form is declared in a similar way, as shown in code 7. In traditional ASP. NET applications, forms and controls are processed differently, which is very different from mobile WEB pages. The biggest difference is that developers can create multiple forms in the same mobile WEB page and freely navigate between these forms without sending them back to the server. This feature can be used to reduce the bandwidth constraints of mobile devices and greatly reduce the amount of data that can be communicated with servers. In other words, mobile devices are displayed in Forms rather than pages as traditional ASP. NET programs do. When we use a mobile device to browse information on different screens, we may not jump to different pages, but jump between different forms on the same page.

 
 
  1. 01 〈%@ Page Language="C#" AutoEventWireup="true"   
  2. CodeFile="MobileDefault.aspx.cs" 
  3. 02 Inherits="MobileDefault" % 〉  
  4. 03 〈%@ Register TagPrefix="mobile"   
  5. Namespace="System.Web.UI.MobileControls"   
  6. 04 Assembly="System.Web.Mobile" % 〉  
  7. 05 〈html xmlns="http://www.w3.org/1999/xhtml"  〉  
  8. 06 〈body 〉  
  9. 07 〈mobile:Form id="Form1" runat="server" 〉  
  10. 08 〈mobile:Label id="lblID" Runat="server" 〉  
  11. Customer ID〈/mobile:Label 〉  
  12. 09 〈mobile:TextBox id="txtCustID" Runat="server" 〉  
  13. 〈/mobile:TextBox 〉  
  14. 10 〈mobile:Command id="cmdGetCustomer"   
  15. Runat="server" 〉Find Customer  
  16. 11 〈/mobile:Command 〉  
  17. 12 〈/mobile:Form 〉  
  18. 13 〈/body 〉  
  19. 14 〈/html 〉 

The Development View of WEB forms in ASP. NET mobile development Visual Studio 2005 provides three views for the design and development of ASP. NET mobile WEB forms. These three views are the design view, HTML view, and Code view. We can switch between these views based on different development requirements. Now let's make a brief summary of the three views.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.