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 !




Sample mobile Web application from ASP.Net mobile controls


Posted Date: 27 Jul 2006    Resource Type: Articles    Category: .NET Framework
Author: Padmasri VemuriMember Level: Gold    
Rating: Points: 13



Sample mobile Web application from ASP.Net mobile controls:

Note : In the sample code I had to remove < /> tags as the content is becoming dynamic.

In this article I want to explain how we can develop mobile applications using ASP.Net Mobile controls in framework 1.1 and compatibility of Mobile forms to ASPX web forms.

Mobile controls are nothing special they will be just similar to normal web controls like Textbox etc, but instead Mobile controls will be preceded by . They were formerly known as the Microsoft Mobile Internet Toolkit (MMIT). With the help of these controls wide range of Web applications can be created for small-screen devices, PDAs, Smart phones and other mobile devices.

To create a Mobile application project like a normal web application we have to go to the following path in Visual studio.net 2003

File --> New --> Project -->Visual C# Projects --> ASP.Net Mobile Web application

It creates a new application with one web form, Global.aspx, web.config and AssemblyInfo.cs similar to our normal ASP.NET web application. However generated files contain a few differences. The below mentioned differences are purely with respect to the look and feel of the application

• As Normal webform will be named as Webform1.aspx default here Mobile web form will named as Mobilewebform1.aspx
• Code behind class of ASPX would refer to System.Web.UI.MobileControls namespace instead of the System.Web.UI.Controls namespace.
• If you open the web.config file it will have two new sections
o MobileControls - contains a key to support cookieless data dictionaries. This setting means that the dictionary contents are stored in the query string so that session and authentication work properly on mobile devices.
o DeviceFilters - This section is much larger and provides several capabilities ASP.NET uses to create device-specific content. You must add or modify this section if you add your own device-specific content. The default section is sufficient in most cases.

To discuss the compatibility to normal web application and web form there are so many topics to be discussed like handling sessionstate, error handling and so on. But in this article I would try to concentrate more on creating a mobile web form with a form to create a login page.

Fist I would name the MobileWebform1.aspx page to Login.aspx

As I discussed earlier Mobile web forms are similar to normal web forms so all your authentication techniques like defining the authentication in web.config to Windows, Passport or Forms will still hold good. In this example I will use forms authentication.

Login.Aspx form would look like:

<@ Page language="c#" Codebehind="Login.aspx.cs" Inherits="MobileWebApplication1.Login" AutoEventWireup="false" />
<@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" />
body
mobile:Form id="Form1" runat="server"

mobile:Label id="lblLogin" runat="server" Enter your Login ID /mobile:Label
mobile:TextBox id="txtLogin" runat="server" mobile:TextBox
mobile:Label id="lblPwd" runat="server" Please Enter your Password mobile:Label
mobile:TextBox id="txtPwd" runat="server" Password="True" /mobile:TextBox
mobile:Command id="cmdSubmit" Runat="server" Submit mobile:Command
mobile:Label id="lblNotAuthenticated" runat="server" mobile:label
/mobile:Form
body


Do the following Modifications in Web.config file. In the credentials if you want to use any algorithm for the password it can be given.

authentication mode="Forms"
forms loginUrl="login.aspx"
credentials
user name="Padma1"
password=" Padma1"/>
user name="Padma2"
password=" padma2"/>
/credentials>
/forms>
/authentication>
authorization>


/authorization>

In the Code Behind of the Login page use this code to authenticate the user. In the includes section don’t forget to include this namespace
System.Web.Security.

if(FormsAuthentication.Authenticate(txtLogin.Text, txtPwd.Text))
{
//Write the logic to redirect to New Page .
}
else
{
lblNotAuthenticated.Text = "Password is Wrong!!!!";
}


I chose this login page because security in Mobile applications is a major thing and I am sure if any one is developing a mobile application they will have the first page as Login page to authenticate the user unless the form which we are showing is not for weather forecasts etc...

Other thing which I want to mention is about testing this application. This application works fine with normal internet explorer but if you want to test using simulators then we can simulators like Microsoft Mobile Explorer or Open wave simulator (which I have used), If you want to test this on a real cell phone with the internet connection then this applications needs to be deployed into a server which is accessible over internet.

Hope this article is helpful to you all. Happy coding!!!!






Responses

Author: DotNetGuts (DNG)    31 Jul 2006Member Level: Diamond   Points : 0
You have done good job. Suggestion : highlightling when required would made your article much more better.


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: Audit Trail Design Concepts in building a secure business application
Previous Resource: What is ADO.NET?
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use