Articles → LIGHT SWITCH 2011 → Confirmation Messagebox In Lightswitch 2011

Confirmation Messagebox In Lightswitch 2011

Software Requirement

  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.

Prerequisite Knowledge

  1. How to create screens in lightswitch application?
  2. How to add buttons in lightswitch application?
  3. What is button’s execute event?

Showmessagebox Method In Lightswitch

Picture shows what are the different parts of the message box in lightswitch
Click to Enlarge

  1. ShowMessageBox(string message) - In this method we are passing message only, but the caption of the messagebox will be the lightswitch’s screen name in which we are displaying this messagebox. On the message box there will be only one button with caption Ok. Using this method you cannot change the caption of messagebox.
  2. ShowMessageBox(string message, string caption, MessageBoxOption button) – This method gives you more flexibility in terms of setting the captions and button types. Here the first parameter is for the message which you want to display, second one is to set the caption of messagebox and third one is to set the type of messagebox. The variable button i.e. third parameter is of type MessageBoxOption. On setting the value of this variable we can control which buttons to be displayed in the messagebox.

  1. Ok – only Ok button will be displayed.
  2. OkCancel – Ok and Cancel button will be displayed.
  3. YesNo – Yes and No button will be displayed.
  4. YesNoCancel – Yes, No and Cancel button will be displayed.

  1. Yes
  2. No
  3. Ok
  4. Cancel
  5. None

Picture shows the code for implementing the message box in lightswitch
Click to Enlarge

Confirmation Message Box

  1. Create a new lightswitch project.
  2. Add new screen in the project.
  3. Add a button inside the screen.
  4. In the button’s execute event write following code

this.ShowMessageBox("Are you sure that you want to delete this item?", "Delete Confirm", MessageBoxOption.YesNoCancel);


Picture shows the output of the message box in lightswitch
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Friday, October 5, 2012


Your Email Id  
Query/FeedbackCharacters remaining 250