Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to Create Mobile Web Application in ASP.Net 2.0

Author: DevASP
Download Source Code : 327_CreatingMobileApp.zip

In this sample application I will try to explain you how you can create a mobile web application in Visual Studio 2005 (VS2005). Here I will discuss three of its controls.

Visual Studio provides many powerful and user friendly tools for creating Mobile Web Application. Creating Mobile Web application is as easy and simple as creating a simple web application. Different controls are also available that helps the developers in creating and managing there applications.

 

To create a mobile web application in ASP.Net 2.0, select new website option from file menu and give name to your project. After creating a website, select Add Item option by right clicking on your project from the solution explorer. When you select the Add Item option a dialog box will be displayed. Select Mobile Web Form from the dialog box and add the following code in your MobileWF.aspx:

 

<mobile:Label ID="lblMsg" Runat = "server" Text = "Get Contact Number" />

 

<mobile:List ID="LDispRecord" Runat="server" DataTextField="UserName" DataValueField="UserID" Decoration="Bulleted" />

 

<mobile:TextBox ID="txtText" Runat = "server" />

 

<mobile:Command ID="cmdShowRecord" Runat="server" Text="Get Contact Number" >Get Contact Number</mobile:Command>

 

<mobile:List ID="LShowRecord" Runat="server" DataTextField="ContactNumber" DataValueField="UserName" Decoration="Numbered" />

 

</mobile:Form>

You can also add the style sheet in your application by draging a droping the Style Sheet Mobile control from the toolbar:

 

<mobile:StyleSheet ID="StyleSheet1" Runat="server">

 

<PagerStyle Alignment="Center" BackColor="#C0FFC0" Font-Name="Verdana" Font-Size="Small" ForeColor="Green" Name="PageStyleSheet" Wrapping="Wrap" ></PagerStyle>

 

 

<mobile:Style BackColor="Gold" Font-Name="Verdana" Font-Size="Small" ForeColor="#404040" Name="WebControlStyle" Wrapping="Wrap">

</mobile:Style>

 

</mobile:StyleSheet>

In above code notice one thing that is you will see “mobile” prefix before each control and this prefix will help you in differentiating between the simple web application and mobile web application. Now double click on the form or press F7 to view the MobileWF.aspx.vb file and add the following code:

 

Dim DBConn As New SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sample Database;UID=YourID;Data Source=YourDatasource")

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

Dim DBAdap As New SqlDataAdapter

Dim DS As New DataSet

 

DBAdap = New SqlDataAdapter("SELECT * FROM  UserRecord", DBConn)

DBConn.Open()

DBAdap.Fill(DS)

 

LDispRecord.DataSource = DS

LDispRecord.DataBind()

 

DBConn.Close()

DBAdap.Dispose()

DBAdap = Nothing

DS.Dispose()

DS = Nothing

 

End Sub   

Notice I have created a global database connection object and one thing more don’t forget to import System.Data and System.Data.SqlClient namespaces. On the cmdShowRecord_Click event add the following code:

 

Protected Sub cmdShowRecord_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdShowRecord.Click

 

DBConn.Open()

Dim DBAdap As New SqlDataAdapter

Dim DS As New DataSet

 

DBAdap = New SqlDataAdapter("SELECT UserName, ContactNumber FROM  UserRecord WHERE UserName='" & txtText.Text & "'", DBConn)

DBAdap.Fill(DS)

LShowRecord.DataSource = DS

LShowRecord.DataBind()

 

DBConn.Close()

DBAdap.Dispose()

DBAdap = Nothing

DS.Dispose()

DS = Nothing

 

End Sub

Article Comments
Hi,

I'm creating a mobile application with VS2005(C#) and couldn't do introduction and auto redirect this page(splash) to login page. Do u know how i do this??

Thanks a lot

Posted on 9/18/2006 10:27:31 AM by Daniel

I want to align mobile web controls in the mobile web form to particullar location. So how can i specify the location?

Posted on 1/18/2007 4:26:37 PM by Sharanjit

im also creating mobile application. vs.Net2003 also asp.net 2.0?

Posted on 1/24/2007 11:57:38 PM by Hermie

hye daniel, ineed your help. ive installed vs2005, but i cant install MMIT. please help me to solve this problem..


Posted on 3/15/2007 2:16:48 AM by hermie

im also creating mobile application. vs.Net2005 also vs.Net2008?

Posted on 1/16/2008 8:08:30 PM by Rodo

How to create a web application like yahoo for the mobile application i.e. It can easily run on the cell phone using asp.net 2.0

Posted on 3/17/2008 8:14:39 AM by Nikhil

i am also try to create a mobile application,plz let me know the proper steps to create a mobile application

Posted on 4/7/2008 8:20:09 AM by sachin

I have working windows mobile application I want to write asp.net mobile web page for tis with vs 2008.
Even I could not start.
Do I need to install MMIT for vs 2008 and is it enough to install it.
I mean Do I need to configure any thing and wher can I download MMIT If I need to install.
I vs there is no web mobile project type.
Ho I can create a web mobile?
Regards
Reside

Posted on 11/7/2008 3:53:32 AM by reside ozsoy

Basically I downloaded your code and opened it with vs 2008.
If I open MobileWF.aspx on the design I am seeing the error creating form1 and error creating control stylesheet1.
I am new so could you please tell me what I should do to get reed of this error?

Posted on 11/7/2008 4:00:28 AM by reside ozsoy

Hi ozsoy!!!

Have you tried to open in vs2005. It works great. Also when you open in VS 2008 have u checked that the form is a web form or a mobile form. :) Check it out.

Posted on 12/9/2008 12:45:15 AM by trendz

How to Create Mobile Web Application in ASP.Net with source code

Posted on 7/22/2009 3:50:16 AM by ambikabathi

Hi i am using VS 2008....I need to develop mobile web application but i dont have the mobile form template........anyone help me to find out how to install the mobile template

Posted on 12/7/2009 11:14:34 AM by mohamed harish

I m developing smart device application in vb.net 2005 and i am not able to add web service in smart device...
Can you help me...?

Posted on 2/7/2010 6:32:07 AM by Mona

Good for freasher

Posted on 2/22/2010 3:32:19 AM by Rahul

i am new to this developing mobile applications using .net.How can i test the page in a virtual mobile device?please give me the details in installing softwares

Posted on 3/26/2010 3:24:58 AM by Abhimanyu

how to create mobile application in .net

Posted on 5/6/2010 5:23:16 AM by Ashish Doorwar

Hi
I already develop my application in vs2005.But now i want to convert this application on mobile application.For that what i do?

Posted on 8/16/2010 3:30:35 AM by Bharati

hy,
i m somin,
i want to create mobile application for home appliances so help me to create this project

Posted on 8/29/2010 12:30:41 AM by SOMIN

hi , i ran ur code in VS 2005 and 2008 but no successed! is there any solution which i can create website and run it on Windows mobile Emulator in VS 2008?

thanks,

Posted on 11/5/2010 6:55:36 PM by lili

Hi...
How to creat WB page..

Posted on 11/20/2010 1:12:08 AM by diwakar

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to Declare and Use Application Variables in ASP.Net

Disclaimer - Privacy
© 2002-2012 DevASP.net