locked
Quesiton about dialogs and modal windows RRS feed

  • Question

  • Folks,

    I'm using a OpenFileDialog in an application (Web) I have built that appears to work fine.  The dialog is launched from a modal window, here a user can select multiple images to upload to the datagrid in the modal.  The problem arises after the user hits the modal OK button to save data and close the modal window.  If the user goes back into the modal window to add more photos they (or I since I'm the only user) get the "Dialogs must be user initiated' error.  However, the OpenFileDialog launches and allows the user to select photos, it's upon hitting the "Open" button in the OFD that the Silverlight error occurs.  Furthermore, the selected photos are still sent up to the grid and can be saved.  It's more of an annoyance, not app breaking.  Now I have found that if, after closing the modal window, I refresh the screen then all is well, I can reopen the modal and add more photos.  One more item to add... while in the modal window I can open and close the OFD as much as is needed, it's not until closing and reopening the modal that I get this.  I've also tested it on different modals in the same screen, you can switch between modals and it works fine, it's not until reopening one that has already been opened (without a refresh) that the security dialog is thrown.

    So am I limited to just needing to refresh the screen and deal with this or is their a way around this?  I get the basics of the Silverlight security feature relating to dialogs and completing the process to make the user initiated, I don't understand the process that is causing the error in this instance.

    Here is what I'm using to launch the OFD (I wish I could give credit with who helped me out with the below code but can't remember):

    partial void ProjectDetail_Created() { this.FindControl("ImagesAddAndEditNew").ControlAvailable += ProjectDetail_ControlAvailable; } void ProjectDetail_ControlAvailable(object sender, ControlAvailableEventArgs e) { var btn = e.Control as System.Windows.Controls.Button; btn.Click += new System.Windows.RoutedEventHandler((s2, e2) => { List<FileInfo> files = new List<FileInfo>(); OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "Images (*.jpg;*.png)|*.jpg;*.png"; if (ofd.ShowDialog().GetValueOrDefault()) //VS debugger points here { //when security dialog files = ofd.Files.ToList(); //is thrown } this.Details.Dispatcher.BeginInvoke(() => { foreach (var fi in files) { byte[] img = ReadAllBytes(fi); var image= this.ComplianceReviewPhoto.AddNew(); iamge.ImageData = img; image.Filename = fi.Name; } }); }); }

    Wednesday, January 15, 2014 4:08 AM

All replies

  • Hi billym

    According to your description above, it seems that there is something wrong during you save your data, and it also seems that this issue occurs occasionally.

    Cleaning and rebuilding your current Project first (Right-click > Clean, Right-click Rebuild respective) and see if that makes any difference at all. 

    For this issue, I think this issue is related to SaveFileDialog, please check your code on your side.

    hope it helps.

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Edited by Angie Xu Thursday, January 23, 2014 1:27 AM
    • Marked as answer by Angie Xu Thursday, January 23, 2014 1:28 AM
    • Unmarked as answer by billym99 Thursday, January 30, 2014 7:32 PM
    Friday, January 17, 2014 2:15 AM
  • Angie,

    I appreciate the reply.  I've cleaned/rebuilt multiple times but no luck.  I'm not sure what you mean by the issue possibly being related to the "SaveFileDialog".  If you mean that somewhere in the save() is the issue I don't believe this to be the case.  I can open/close the OpenFileDialog in a screen as many times as I want, save data, etc. with no issues.  The problem arises after launching the OpenFileDialog, choosing a file, uploading/saving, and then switching focus to another tab (or modal window).  If I do this, then the next time I visit that tab (or modal window) I launched the OFD from I then get the "dialogs must be user initiated error", despite the operation actually completing (even though the error is thrown the file(s) is still uploaded to the grid).  If a screen refresh was performed in between switching focus then there is no issue.


    *EDIT - Angie, to clarify about saving data I added dataworkspace.applicationdata.savechanges() in the loop, so each photo is saved just after it is added to the grid.
    • Edited by billym99 Thursday, January 30, 2014 7:50 PM
    Thursday, January 30, 2014 7:38 PM