Prevent User From Pressing Preview Multiple Times

Posted by: jonathan.brower on 9 November 2023, 5:32 am EST

    • Post Options:
    • Link

    Posted 9 November 2023, 5:32 am EST

    I’m using the ASP.NET WebViewer control in an MVC project and I’ve got an issue where some of my reports take a little while to calculate/render, so when a user gets impatient they click the Preview button in the WebViewer multiple times, which causes the queries to run multiple times, which in turn slows the sql server down and slows all the reports down etc.

    I’m not sure if I’m doing something incorrectly, but I wouldn’t be surprised lol. Is there a way to disable the Preview button within the WebViewer until the report is done rendering? Or is there another approach that I should be taking?

  • Posted 9 November 2023, 9:47 pm EST

    Hi Jonathan,

    Could you please let us know which preview button of the Web Viewer are you talking about? If possible then please share a screenshot or a GIF.

    Although, As per your use case I would not recommend you to disable the preview button. As disabling the Preview button would work for one computer but if reports are loaded from multiple machines it would still cause the same on the Server.

    I would rather suggest you the following solutions for fixing this issue:

    1. Caching: I would suggest you to create another server in between which caches the request in regular time interval and it will reduce the time it takes to complete each request.
    2. Indexing in SQL Server: A SQL index is used to retrieve data from a database very fast. If you haven’t already implemented indexing I would highly suggest you to do so as it will reduce the time of queries from multiple minutes to a just a few seconds.
    3. Service Worker: you may create a client side service worker which checks if a data request is made multiple times and return the cached data and does not actually make any new request to SQL Server.

    As per my understanding of your use case I believe these solutions would be much more robust and helpful for the issue that you are facing. For more details on the above mentioned solutions please refer to the following websites:

    I hope this helps!

  • Posted 10 November 2023, 3:09 am EST - Updated 10 November 2023, 3:14 am EST

    Thanks for suggestions. I will look into implementing them in the near future. In the meantime, I’ve attached a screenshot of the button I’m referring to.

  • Posted 13 November 2023, 8:38 pm EST

    Hi Jonathan,

    There is no public API for modifying the Preview button but you can create a custom solution for this by adding custom CSS to disable the button on button click and enable the button when documentLoaded API is called.

    An alternative way would be to simply show a loading screen in front of the Viewer container when the button is clicked and hide it when the documentLoaded API is called.

    Please refer to the attached sample. I hope it helps!

    JSViewerCustomPreviewBtn.zip

  • Posted 15 November 2023, 4:51 am EST

    Thanks so much for the help!

  • Posted 15 November 2023, 3:30 pm EST

    Hi Jonathan,

    I am glad to know your issue is resolved!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels