locked
Custom Modal Dialog Not Showing Correctly RRS feed

  • Question

  • I've got a simple modal dialog that I'm trying to show. When I call Application.ShowMyCustomScreen() I get a new tab with a giant button. When the button is clicked I get my dialog.

    What could cause this?

    Thanks

    Wednesday, April 13, 2011 5:15 PM

Answers

  • The modal dialog in LS is a child window embedded inside a screen.  It can only be used by that screen, but is not a reusable object.

    You can define the dialog directly inside the screen where you want to use it.   By default, it shows a button to bring up the dialog.  You can set property to hide that button, and use OpenModalWindow method to open a dialog.

     


    LLF
    Wednesday, April 13, 2011 5:42 PM

All replies

  • The modal dialog in LS is a child window embedded inside a screen.  It can only be used by that screen, but is not a reusable object.

    You can define the dialog directly inside the screen where you want to use it.   By default, it shows a button to bring up the dialog.  You can set property to hide that button, and use OpenModalWindow method to open a dialog.

     


    LLF
    Wednesday, April 13, 2011 5:42 PM
  • How do I do that? Is there documentation that describes OpenModalWindow?

    Wednesday, April 13, 2011 8:35 PM
  • I found it. It appears that this.OpenModalWindow("ControlName") does the trick.
    Wednesday, April 13, 2011 8:39 PM
  • Well, I thought it was working, but it's actually throwing an error. I put the name of the modal screen from the property sheet in the designer, but it says that it can't be found.

    Wednesday, April 13, 2011 9:15 PM
  • Here is an example of overriding the [Add] button on a grid to open a modal window and to also cancel the modal window changes if the user clicks on the [X] button in the top right corner of the modal window:

    partial void ContractTypeDefaultsAddAndEditNew_Execute()
    {
        // create a new record
        var newObj = this.ContractTypeDefaults.AddNew();

        // show modal add dialog (note: a bug in B2 forces you to open the modal window before adding the event handler)
        this.OpenModalWindow("ContractTypeDefault_ModalWindow");

        // add an event handler to trap user clicking [X] in top right corner
        var modalWindow = this.FindControl("ContractTypeDefault_ModalWindow");
        modalWindow.ControlAvailable += new EventHandler<ControlAvailableEventArgs>(ModalWindow_ControlAvailable);
    }

    void ModalWindow_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
        var window = (ChildWindow)e.Control;
        window.Closed += new EventHandler(ModalWindow_Closed);
    }

    void ModalWindow_Closed(object sender, EventArgs e)
    {
        var window = (ChildWindow)sender;
        if (!window.DialogResult.HasValue)
        {
            // modal dialog closed by user clicking [X] in top right corner
            this.ContractTypeDefaults.SelectedItem.Details.DiscardChanges();
        }
        window.Closed -= ModalWindow_Closed;
    }

    EDIT: Here is the code for when the user clicks the OK or Cancel buttons that you add to the modal window:

    partial void ModalWindowSubmit_Execute()
    {
        // user clicked OK so just close modal window
        this.CloseModalWindow("ContractTypeDefault_ModalWindow");
    }

    partial void ModalWindowCancel_Execute()
    {
        // user clicked Cancel so discard changes and close modal window
        this.ContractTypeDefaults.SelectedItem.Details.DiscardChanges();
        this.CloseModalWindow("ContractTypeDefault_ModalWindow");
    }

    Hope this helps


    Xander


    • Edited by novascape Wednesday, April 13, 2011 11:40 PM
    Wednesday, April 13, 2011 10:58 PM
  • Hi Xander,

    That's a fantastic example, thanks!

    I'm just starting to get into modal windows.

    Yann

    Wednesday, April 13, 2011 11:08 PM
  • Hi Yann,

    Glad is it of use. I added the OK and Cancel modal window button methods above for completeness.

    Regards


    Xander
    Wednesday, April 13, 2011 11:38 PM
  • Xander,

    I found that in order to be able to resolve ChildWindow (which you use to case "sender"), I had to add a reference to the Client project for System.Windows.Controls

    I'm guessing that you had already added that for something previously.

    Until I added that referenence, ChildWindow was not recognised.

    Hope that saves someone some trouble making Xander's excellent code work for them.

    Yann

    Thursday, April 14, 2011 12:02 AM
  • I thought my memory was playing tricks on me, cos I didn't think I saw that code there before, lol..
    Thursday, April 14, 2011 12:02 AM
  • And here is a VB translation for us VB guys:

    Private Sub ContractTypeDefaultsAddAndEditNew_Execute()
     ' create a new record
     Dim newObj = Me.ContractTypeDefaults.AddNew()

     ' show modal add dialog (note: a bug in B2 forces you to open the modal window before adding the event handler)
     Me.OpenModalWindow("ContractTypeDefault_ModalWindow")

     ' add an event handler to trap user clicking [X] in top right corner
     Dim modalWindow = Me.FindControl("ContractTypeDefault_ModalWindow")
     AddHandler modalWindow.ControlAvailable, AddressOf ModalWindow_ControlAvailable
    End Sub

    Private Sub ModalWindow_ControlAvailable(ByVal sender As Object, ByVal e As ControlAvailableEventArgs)
     Dim window = CType(e.Control, ChildWindow)
     AddHandler window.Closed, AddressOf ModalWindow_Closed
    End Sub

    Private Sub ModalWindow_Closed(ByVal sender As Object, ByVal e As EventArgs)
     Dim window = CType(sender, ChildWindow)
     If (Not window.DialogResult.HasValue) Then
      ' modal dialog closed by user clicking [X] in top right corner
      Me.ContractTypeDefaults.SelectedItem.Details.DiscardChanges()
     End If
     RemoveHandler window.Closed, AddressOf ModalWindow_Closed
    End Sub

    EDIT: TypeOf Here Is the code for when the user clicks the OK or Cancel buttons that you add to the modal window:

    Private Sub ModalWindowSubmit_Execute()
     ' user clicked OK so just close modal window
     Me.CloseModalWindow("ContractTypeDefault_ModalWindow")
    End Sub

    Private Sub ModalWindowCancel_Execute()
     ' user clicked Cancel so discard changes and close modal window
     Me.ContractTypeDefaults.SelectedItem.Details.DiscardChanges()
     Me.CloseModalWindow("ContractTypeDefault_ModalWindow")
    End Sub

    Thursday, April 14, 2011 12:05 AM
  • I can't even get past this.OpenModalWindow("ScreenName"); It claims that it can't find the name of the screen even though I have the exact name that shows up in the property sheet for that screen.

    Edit: NVM, I was trying to pass the whole screen, apparently it has to have a child control.

    Thursday, April 14, 2011 4:36 PM
  •  How do I add a modal window to a screen?
    Thursday, April 14, 2011 9:25 PM
  • Hi,

    Add a new group & select "Modal Window" as its type, or change the type of an existing group control to "Modal Window".

    Yann

    • Proposed as answer by Yann Duran Thursday, April 14, 2011 11:09 PM
    Thursday, April 14, 2011 11:09 PM
  • Hi Xander,

     

    Is there a reason why you are not actually saving your data  when the user clicks submit?

    partial void ModalWindowSubmit_Execute()
    {
        // user clicked OK so just close modal window
        this.CloseModalWindow("ContractTypeDefault_ModalWindow");
    }

    Would it be correct to do it this way?

    this

     

    .ContractTypeDefaults.Screen.Save();

    thanks

    paul.

     
    paul van bladel
    Wednesday, April 20, 2011 3:31 PM
  • Hi Paul,

    Doing this would save any *other* changes that may have been made to controls on the screen that weren't part of the modal window.

    That may, or may not, be desirable, depending on circumstances.

    Leaving it up to the user to click "Save" gives them the chance to "throw away" all changes made if they decide they don't want the changes.

    Does that help?

    Yann

    Thursday, April 21, 2011 12:25 AM