Showing posts with label Mobile Web Application. Show all posts
Showing posts with label Mobile Web Application. Show all posts

Tuesday, March 20, 2007

.NET : Building Mobile Web Forms for BlackBerry

Note: This article is written by me and was published in the BlackBerry Developers Journal in July 2005

In this article I will show how to build a simple travel request form using ASP .NET that sends form data to specific users as email.
Let's get started...

Note: VS 2005 does not have Mobile Forms Template. You can download it here. Thanks Omar!!

Open Microsoft Visual Studio® .NET and start a new project of type "ASP .NET Mobile Application". In Form1.aspx, create an interface as shown below.
Double click on "Submit" and then enter in the following code:

using System.Web.Mail;
private void Command1_Click(object sender, System.EventArgs e)
{
//perform validation
if(txtMailTo.Text=="" || txtFrom.Text=="")
{
Response.Write("Please fill in to and from fields");
}
//If the code is validated then take all
//the input values and form an HTML message
else
{
MailMessage m=new MailMessage();

//Get input values from the form
m.To= txtMailTo.Text;
m.From=txtFrom.Text;
m.Subject="Travel Request";
m.BodyFormat=MailFormat.Html;
m.Body= "Name : "+TextBox1.Text +""+
"Department : "+ TextBox2.Text +""+
"Cost Center and GL : " + TextBox3.Text +""+
"Manager : "+ Textbox4.Text +""+
"Name of VP to Authorize : " + Textbox5.Text +""+
"Destination : "+ Textbox6.Text +""+
"Date and Time of Departure : " + Textbox7.Text +""+
"Additional remarks :"+ Textbox18.Text ;

//Send the message
System.Web.Mail.SmtpMail.Send(m);

//Redirect the user to another page saying
// message was sent successfully
this.RedirectToMobilePage("MsgSend.aspx");
}
}
Post the page to your internal web server, access it from your BlackBerry device, enter some test data and then press the submit button to send an email to the user in HTML format. This application can also be extended to send form data to a database instead of an email.