This Forum is ARCHIVE only
For LightSwitch questions,
please use the official forums at:

http://social.msdn.microsoft.com/forums/en-US/lightswitch/threads


Remove Unsaved Records On Close oF Popup
Last Post 21 Jun 2011 09:19 PM by admin. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev
You are not authorized to post a reply.
Author Messages Informative
Michael WashingtonUser is Offline
Send Private Message
Posts:1313
Avatar

--
05 Jun 2011 05:53 AM
    #region Respond_Execute
    partial void Respond_Execute()
    {
        this.OpenModalWindow("MessageNew");
     
        // Wire up an event to detect when the Modal window is closed
        this.FindControl("MessageNew").ControlAvailable +=
            new EventHandler(PostsListDetail_ControlAvailable);
    }
    #endregion
     
    #region PostsListDetail_ControlAvailable
    void PostsListDetail_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
        ChildWindow window = (ChildWindow)e.Control;
        window.Closed += new EventHandler(MessageNew_Closed);
    }
    #endregion
     
    #region MessageNew_Closed
    void MessageNew_Closed(object sender, EventArgs e)
    {
        ChildWindow window = (ChildWindow)sender;
        if (!(window.DialogResult.HasValue))
        {
            // Remove unsaved records           
            foreach (Message message in this.DataWorkspace.ApplicationData.Details.GetChanges()
                .AddedEntities.OfType < message > ())
            {
                message.Details.DiscardChanges();
            }
        }
    }
    #endregion
     
    #region SaveMessage_Execute
    partial void SaveMessage_Execute()
    {
        this.CloseModalWindow("MessageNew");
        this.Save();
    }
    #endregion
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    kchristoUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:14
    Avatar

    --
    21 Jun 2011 04:09 PM
    One question. In my code ChildWindow is not available, what assembly is it defined in, and shouldn't it be referenced in the Client project by default? Am I missing something?
    1+1 = 3 for very large values of 1
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1313
    Avatar

    --
    21 Jun 2011 09:19 PM
    In my code ChildWindow is not available, what assembly is it defined in, and shouldn't it be referenced in the Client project by default? Am I missing something?


    Switch to File View, and add a Reference, in the Client project, to System.Windows.Controls (this is so we can programmatically interact with a PopUp as a ChildWindow).

    See a full example here:
    http://www.codeproject.com/KB/silve...rSale.aspx
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    You are not authorized to post a reply.


    Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation