DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Displaying the MessageBox in PhoneGap for Windows Phone

Displaying the MessageBox in PhoneGap for Windows Phone

Senthil Kumar user avatar by
Senthil Kumar
·
Mar. 27, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
6.81K Views

Join the DZone community and get the full member experience.

Join For Free

The PhoneGap API provides the method “notification.alert” to display the alert or message box to the end user in the Windows Phone App.

For example , if you want to display the messagebox on the click of the button , include the following

<script type="text/javascript">

function Button1_onclick()

{ navigator.notification.alert("Hi"); }

</script>

<p>

<input id="Button1" type="button" value="Click" onclick="return Button1_onclick()" />

</p>

When the user clicks on the button “Button1″ , you should see a message box similar to the native Windows Phone MessageBox :)

The function navigator.notification.alert accepts the following parameters

  • Message – Dialog message to be displayed on the messagebox
  • callback function – function to be invoked when the dialog is dismissed
  • Title – Title to be displayed on the Dialog. Note that by default this is “Alert” as seen in the above screenshot
  • Name for Button – Name or caption of the button to be displayed



function Button1_onclick()
{
navigator.notification.alert("Welcome",null,"Custom Title","Custom name");
}
Note that the fourth parameter , the name or caption of the button remains “OK” even when you try to provide a custom name.



Now I will show you how to create a MessageBox with confirmation ( OK and Cancel ) using PhoneGap.  If you were doing a Windows Phone Development using Silverlight and C# , you would use the below code to display the messagebox with confirmation.

 

MessageBox.Show("Do you want to continue ?", "Confirmation", MessageBoxButton.OKCancel);

The MessageBox.Show returns MessageBoxResult.

The PhoneGap provides the navigator.notification.confirm method to do the same.

You could use the notification.confirm method to display a Confirmation Dialog in Windows Phone using PhoneGap.

navigator.notification.confirm accept the following parameters

  • Message – Dialog message to be displayed on the messagebox
  • callback function – function to be invoked when the dialog is dismissed
  • Title – Title to be displayed on the Dialog. Note that by default this is “Alert” as seen in the above screenshot
  • Names for Button – Name or caption for the button to be displayed.

Since MessageBox.Show has only 2 MessageBoxButton’s OK and OK, Cancel , you will notice that the Names for Button will always be OK and Cancel in Windows Phone despite what is specified.

function Button1_onclick()
{
navigator.notification.confirm('Do you Want to Continue ?',null, 'Confirmation'

Now , if you want to know which button was clicked, include the function in the 2nd parameter of the confirm method like the below sample code.

 

<script type="text/javascript">

function selectedbutton(button)

{

navigator.notification.alert('You clicked ' + button.toString());

}

function Button1_onclick()

{

navigator.notification.confirm('Do you Want to Continue ?', selectedbutton, 'Confirmation');

}

</script>


I hope this tutorial has been helpful!

Windows Phone

Published at DZone with permission of Senthil Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 8 Reasons the Consequences of Bad Data Are More Severe
  • Deploying Java Applications to AWS Elastic Beanstalk
  • Spring, IoC Containers, and Static Code - Design Principles
  • Instancio: Test Data Generator for Java (Part 2)

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo