C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Mobile Web Development in ASP.NET - Part 2


Posted Date: 13 Mar 2006    Resource Type: Articles    Category: Web Applications
Author: Balamurali BalajiMember Level: Diamond    
Rating: Points: 10



Introduction



The first part of the article dealt with the Microsoft Mobile Internet ToolKit and Visual Studio environment and configuration settings required for creating a mobile based web application in ASP.NET. In the second part, I discuss few mobile controls and how to develop mobile pages that run on a browser or emulator…

ASP.NET Mobile Controls



A developer can create ASP.NET mobile Web Forms pages consisting of controls either in the ASP.NET Mobile Designer or with any text editor. Many of the controls are similar to desktop controls in Web Forms and to GUI controls in other programming languages, such as Microsoft Visual Basic.

MobilePage



This is the base class for all mobile ASP.NET pages. As such, the MobilePage control provides the outermost layer of all the containers in an ASP.NET mobile Web application. It is the only container associated with a URL and primarily contains style and context information common to all controls.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="c#" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>

A mobile page requires two directives. The first directive instructs the ASP.NET page framework to use MobilePage as the base class for the page. The Inherits attribute is required. If the page inherits directly from a MobilePage object, the Inherits attribute must be set to the System.Web.UI.MobileControls.MobilePage namespace. If the page inherits from a code-behind class, the name of the class must be specified instead. The Language attribute is optional; you can set it to the language used on the page, as with any other Web Forms page.

The second directive registers the namespace used by ASP.NET mobile controls that have the mobile prefix. This allows you to declare mobile controls on the page by using the mobile prefix as below.




A MobilePage object can contain the following controls.

System.Web.UI.MobileControls.Form

A MobilePage object must contain at least one Form control and can contain more than more than one Form control.

System.Web.UI.MobileControls.Stylesheet

A style sheet is not required for a MobilePage object. A MobilePage control may or may not have a Stylesheet control.

Example1



This example creates a mobile page and a form, and then adds a label to the form.


<%@ Page Inherits= "System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>

<mobile:Form runat="server">
<mobile:Label runat="server">
My First MobilePage with some controls in it
</mobile:Label>
</mobile:Form>


List Control



It renders a list of items to a mobile device. This control supports templated rendering through device template sets, and it supports internal pagination just as you find it in datalist control in ASP.NET. For information on Template Sets and Templated Controls or Pagination, I will discuss them in the later part of the article.

List control has both Static and Interactive Modes

Static mode

- The control behaves like a static list. Static list items can be declared as item child elements.

Interactive mode

- The control renders items as interactive elements.

The behavior of these modes is based on the presence of an event handler. When an event handler is not present, the control is set to static mode. When an event handler is present, the control is set to interactive mode, in which each item is an interactive element that generates an event when clicked.

You can optionally place DeviceSpecific/Choice construct inside a list control

The following controls can contain one or more List controls.

System.Web.UI.MobileControls.Form

System.Web.UI.MobileControls.Panel



A List control may or may not contain the following controls.

System.Web.UI.MobileControls.DeviceSpecific


System.Web.UI.MobileControls.Item

.

Device Templates in List control


HeaderTemplate

The header template is rendered at the beginning of the list. In paginated mode, the header is rendered on each page.

FooterTemplate

The footer template is rendered at the end of the list. In paginated mode, the footer is rendered on each page.

ItemTemplate

The item template is rendered for each list item.

AlternatingItemTemplate

If defined, an alternating item template is rendered instead of the item template for even items. For example, the second item is an alternating template, as is the fourth item, as is every subsequent even-numbered item.

SeparatorTemplate

The separator template is rendered between two items.

Example2



The following example displays a list of fruit. When you select a fruit, the control displays its price.

<%@ Page Inherits= "System.Web.UI.MobileControls.MobilePage"
Language="C#" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>

<script language="c#" runat="server">
protected void ListFruit_Click(Object source, ListCommandEventArgs e)
{
String selectedFruit = "You selected " + e.ListItem.Text +
" at " + e.ListItem.Value + " per pound.";
PriceLabel.Text = selectedFruit;
ActiveForm = Price;
}
</script>

<mobile:Form id="Fruits" runat="server" BackColor="Cyan">
<mobile:Label runat="server" id="label1">Select a Fruit!</mobile:Label>
<mobile:List runat="server" id="ListFruit"
OnItemCommand="ListFruit_Click" >
<item Text="Apples" Value="50 Rupees per Kg" />
<item Text="Bananas" Value="1 Rupee" />
<item Text="Grapes" Value="10 Rupees per Kg" />
<item Text="Oranges" Value="30 Rupees per Kg" />
</mobile:List>
</mobile:Form>
<mobile:Form id="Price" runat = "server">
<mobile:Label runat="server" id="PriceLabel"/>
</mobile:Form>


Summary



The second part of the series has discussed two mobile controls, List and Label, placed in a mobile form container. Note that the Example2 has two mobile forms in a mobile page. In the Part3 of the article, you would get to know about more of the mobile controls.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Mobile Web Development in ASP.NET - Part 1
Previous Resource: Mobile Web Development in ASP.NET - Part 3
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use