dialogs must be user-initiated

12 posts, 0 answers
  1. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 04 Apr 2012 Link to this post

    I have just upgraded to the latest build (not the IB)
    And i started getting an error while trying to print.

    Here is my code, which i have pretty much taken from the sample:

    private bool CanPrint(object param)
            {
                return true;
            }
     
            private void Print(object param)
            {
                RadGridView grid = (RadGridView)param;
                RadRichTextBox rtb = new RadRichTextBox() { Height = 0 };
     
                rtb.Name = "RadRichTextBox1";
     
                Grid parent = grid.ParentOfType<Grid>();
                if (parent != null && parent.FindName(rtb.Name) == null)
                {
                    parent.Children.Add(rtb);
                    rtb.ApplyTemplate();
                }
     
                rtb.Dispatcher.BeginInvoke((Action)(() =>
                {
                    rtb.Document = CreateDocument(grid);
                }));
     
                rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);
            }
     
            private RadDocument CreateDocument(RadGridView grid)
            {
                List<GridViewBoundColumnBase> columns = (from c in grid.Columns.OfType<GridViewBoundColumnBase>()
                                                         orderby c.DisplayIndex
                                                         select c).ToList();
     
                Telerik.Windows.Documents.Model.Table table = new Telerik.Windows.Documents.Model.Table();
     
                RadDocument document = new RadDocument();
                Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
                section.Blocks.Add(table);
                 
                document.Sections.Add(section);
     
                AddDataRows(table, grid.Items, columns, grid);
     
                return document;
     
            }


    I did get this error once before when i had a breakpoint in the code before i upgraded from Q3 release.
    But now that i am using Q1 2012 release i get this error every time.

    My code is in a viewmodel.


  2. Andrew
    Admin
    Andrew avatar
    140 posts

    Posted 09 Apr 2012 Link to this post

    Hello Andrew,

    The problem you are seeing resides in the very core of Silverlight. In Silverlight you can perform certain actions only when they are user-initiated (that would mean on a button click for example). Here you are opening a save file dialog when a button is clicked which is correct. But there is one more thing. Silverlight has a timeout limit during which the dialog must be shown. If that doesn't happen, a SecurityException is thrown.
    The thing is your grid is too big so the creation of a RadDocument containing all information takes too long and the dialog tries to open too late when this timeout has already been exceeded.
    You can create two buttons for example - one to prepare the document and one to print it. We know this is uncomfortable and not so user friendly but unfortunately is the only way to overcome this Silverlight limitation.

    Please revise and get back to us with your opinion.

    All the best,
    Andrew
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 09 Apr 2012 Link to this post

    Dear Andrew

    I tested this theory by removing all the code that builds the table, in fact all the code except the call to print the document. 
    In this case an empty document. The error still occurs. It happens virtually instantaneously after i press the button.

    My new code:
    RadRichTextBox rtb = new RadRichTextBox() { Height = 0 };
     
    rtb.Name = "RadRichTextBox1";
    rtb.Document = new RadDocument();
    rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);


    I am afraid that your theory does not appear to apply here. There must be another reason for this error.
  5. Andrew
    Admin
    Andrew avatar
    140 posts

    Posted 11 Apr 2012 Link to this post

    Hello Andrew,

    I checked your account to see what version you previously worked with. It turns out we have added a lot of features since then and that has slowed down the initialization of RadRichTextBox.

    As a workaround we would suggest initializing and adding the RadRichTextBox to the visual tree somewhere else (in the constructor of the page for example) and only setting the Document in the button click event handler. However, it is possible that this approach also results in the same exception, if the document is too big and its creation and layout require more time than the limit of the print dialog.

    Kind regards,
    Andrew
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 18 Apr 2012 Link to this post

    So in other words there is no way to guaranty that the printing will not cause an exception? 
  7. Andrew
    Admin
    Andrew avatar
    140 posts

    Posted 19 Apr 2012 Link to this post

    Hello Andrew,

    The error occurs because you instantiate the RadRichTextBox (which takes quite some time), assign a document (which takes time too) and if the document is big that takes additional time.

    In order to ensure that the timeout of the PrintDialog will not be exceeded, you can create a print-preview like window with RadRichTextBox and a Print button in it. When the user decides to print the grid view and clicks a button, build the document and show in in a window with RadRichTextBox. You can have a button in this window which invokes only the print command. In this way, the successful printing of the document would be guaranteed.

    I hope you find this solution acceptable.

    Kind regards,
    Andrew
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Gitit
    Gitit avatar
    4 posts
    Member since:
    Jun 2015

    Posted 09 Jun 2015 Link to this post

    Is there any fix to this issue in a later version ?

    I'v downloaded the last version, and i get the same error.

    (my code was copied from your demos site: http://demos.telerik.com/silverlight/#GridView/PrintAndExportWithRadDocument))

    Also didn't succeed to print from the online demo itself.

    ANY solution to that ?? 

    the only print that worked for me is to use PrintToHtml method that doesn't seem to allow any styling at all.

    Thanks,

    Gitit

     

  9. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 10 Jun 2015 Link to this post

    Hi Gitit,

    The discussed issue is related to a limitation in the framework and we are not aware of any released fix for it. At this point the only workaround of this limitation is the one suggested below by Andrey.

    I tested our demos and couldn't reproduce the described behavior - the document is printed as expected. Are you testing with the same data or with another? Could you give us exact steps to reproduce this in order to test on our end and check if there is something else preventing you from printing?

    Regards,
    Tanya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Gitit
    Gitit avatar
    4 posts
    Member since:
    Jun 2015

    Posted 11 Jun 2015 in reply to Tanya Link to this post

    Thank you for your reply.

    I'm sorry to hear that there is no fix to this problem.

    Meanwhile I'v succeeded to print only grid view with several rows (The grid view contains 20 columns).

    I guess I'll have no choise but to implement the suggested solution.

    Thanks,

    Gitit

  11. Gitit
    Gitit avatar
    4 posts
    Member since:
    Jun 2015

    Posted 18 Jun 2015 Link to this post

    My gridview contains row details that has child gridview. 

    How can I print my grid including its row details ?

    No matter what I do I wasn't able to print it, only the parent grid.

    I'll be glad to hear if you have any solution.

    Thanks, 

    Gitit

  12. Petya
    Admin
    Petya avatar
    975 posts

    Posted 23 Jun 2015 Link to this post

    Hello Gitit,

    I'd suggest adopting the approach demonstrated in this online example which utilizes RadDocument. You can subscribe to the ElementExporting event of RadGridView when exporting the document, iterate the nested RadGridViews and export them separately. You can also take a look at this demo showing export of RowDetails.

    I hope this is useful.

    Regards,
    Petya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  13. Gitit
    Gitit avatar
    4 posts
    Member since:
    Jun 2015

    Posted 23 Jun 2015 in reply to Petya Link to this post

    thanks, I'v already did it.
Back to Top
DevCraft banner