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.

4 comments:

Blackberry Application & Development said...

Hello,
Nice post,
Blackberry's success has led to more than 28 million users of this smart phone brand.
blackberry application developmen

Danial123 said...

We specialize in creating and supporting custom mobile sales applications and websites for businesses. mobile business apps
iphone application design

viji said...

Heya¡­my very first comment on your site. ,I have been reading your blog for a while and thought I would completely pop in and drop a friendly note. . It is great stuff indeed. I also wanted to ask..is there a way to subscribe to your site via email.

Blackberry Development

lee wright said...

You rock