Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
How to display page while long-running process executing?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="lmttag" data-source="post: 2760191"><p>Steven,</p><p>Thank you for the information. It was very helpful.</p><p></p><p>I was able to get the 3rd option (ASP.NET AJAX) pattern working for a simple</p><p>situation. However, my situation is a bit more complex and I'm not sure how</p><p>to use the AJAX pattern and make it work. So, I was hoping that I could</p><p>give you some more info. and check to see if you could assist me.</p><p></p><p>As I mentioned in my original post, I have a page that opens another page</p><p>using the JavaScript window.open function. In the second page, I have no</p><p>controls, no buttons (no buttons to click to cause a postback), no div tags,</p><p>etc. What I'm doing in the second page is generating a SQL Server 2005</p><p>Reporting Services report, rendering it as PDF, and displaying the PDF in</p><p>the second page's browser.</p><p></p><p>For some reports, this generating/rendering of the report can take maybe 20</p><p>seconds. So, I need the page to display an animated gif with a message that</p><p>says "Please wait..." while, in the background, the report is being</p><p>generated. Then when the report is done being generated/rendered, I need</p><p>the animated gif and wait message to go away and have the PDF report</p><p>displayed.</p><p></p><p>I hope this makes sense. Would you be able to provide some suggestions/help</p><p>with this situation?</p><p></p><p>Here's some code snippets from my second page that is generating, rendering,</p><p>and displaying the report.</p><p></p><p>(Nothing in the markup for the page.)</p><p><html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>" ></p><p><head runat="server"></p><p> <title>Generated Report</title></p><p> <link href="../CSS/ReportsStyleSheet.css" rel="Stylesheet"</p><p>type="text/css" /></p><p></head></p><p><body></p><p> <form id="formRenderReport" runat="server"></p><p> <div></p><p> </div></p><p> </form></p><p></body></p><p></html></p><p></p><p>(The code-behind...)</p><p>public partial class Pages_RenderReport : System.Web.UI.Page</p><p>{</p><p> protected void Page_Load(object sender, EventArgs e)</p><p> {</p><p> if (!IsPostBack)</p><p> {</p><p> AddOnPreRenderCompleteAsync(new</p><p>BeginEventHandler(BeginAsyncOperation), new</p><p>EndEventHandler(EndAsyncOperation));</p><p> }</p><p> }</p><p></p><p> private System.IAsyncResult BeginAsyncOperation(object sender, EventArgs</p><p>e, AsyncCallback cb, object state)</p><p> {</p><p> // ...</p><p></p><p> // Connect to Reporting Services</p><p> ReportingExecution.ReportExecutionService rs = new</p><p>ReportingExecution.ReportExecutionService();</p><p> rs.Credentials =</p><p>System.Net.CredentialCache.DefaultCredentials;</p><p></p><p> // Local Reporting Services variables</p><p> byte[] result = null;</p><p> string format = "PDF";</p><p> string format = outputformat;</p><p> string historyID = null;</p><p> string devInfo = null;</p><p> string encoding;</p><p> string mimeType;</p><p> string extension;</p><p> ReportingExecution.Warning[] warnings = null;</p><p> string[] streamIDs = null;</p><p></p><p> // ...</p><p></p><p> try</p><p> {</p><p> // Set all the Reporting Services variables and</p><p>parameters and render the report</p><p> ReportingExecution.ExecutionInfo execInfo = new</p><p>ReportingExecution.ExecutionInfo();</p><p> ReportingExecution.ExecutionHeader execHeader = new</p><p>ReportingExecution.ExecutionHeader();</p><p> rs.ExecutionHeaderValue = execHeader;</p><p> execInfo = rs.LoadReport(reportPath1, historyID);</p><p> rs.SetExecutionParameters(parameters, "en-us");</p><p> System.String SessionId =</p><p>rs.ExecutionHeaderValue.ExecutionID;</p><p> result = rs.Render(format, devInfo, out extension, out</p><p>mimeType, out encoding, out warnings, out streamIDs);</p><p> execInfo = rs.GetExecutionInfo();</p><p></p><p> // Force the render out of the report to the browser</p><p> Response.Clear();</p><p> Response.ClearContent();</p><p> Response.ClearHeaders();</p><p> Response.AppendHeader("content-length",</p><p>result.Length.ToString());</p><p></p><p> switch (outputformat)</p><p> {</p><p> case "EXCEL":</p><p> Response.ContentType =</p><p>"application/vnd.ms-excel"; // Seems to work</p><p> break;</p><p> case "MHTML":</p><p> Response.ContentType = "message/rfc822";</p><p> break;</p><p> case "PDF":</p><p> Response.ContentType = "application/pdf";</p><p> break;</p><p> default:</p><p> Response.ContentType = "application/pdf";</p><p> break;</p><p> }</p><p></p><p> Response.BinaryWrite(result);</p><p> Response.Flush();</p><p> Response.Close();</p><p> Response.End();</p><p> }</p><p> catch (System.Exception ex)</p><p> {</p><p> // An exception occurred while trying to generate and</p><p>render the report</p><p> }</p><p></p><p></p><p> // Just needed to get a IAsyncResult to return</p><p> System.Net.WebRequest hwr =</p><p>System.Net.WebRequest.Create("<a href="http://localhost/">http://localhost/</a>");</p><p> return hwr.BeginGetResponse(cb, state);</p><p> }</p><p></p><p> private void EndAsyncOperation(System.IAsyncResult ar)</p><p> {</p><p> //</p><p> }</p></blockquote><p></p>
[QUOTE="lmttag, post: 2760191"] Steven, Thank you for the information. It was very helpful. I was able to get the 3rd option (ASP.NET AJAX) pattern working for a simple situation. However, my situation is a bit more complex and I'm not sure how to use the AJAX pattern and make it work. So, I was hoping that I could give you some more info. and check to see if you could assist me. As I mentioned in my original post, I have a page that opens another page using the JavaScript window.open function. In the second page, I have no controls, no buttons (no buttons to click to cause a postback), no div tags, etc. What I'm doing in the second page is generating a SQL Server 2005 Reporting Services report, rendering it as PDF, and displaying the PDF in the second page's browser. For some reports, this generating/rendering of the report can take maybe 20 seconds. So, I need the page to display an animated gif with a message that says "Please wait..." while, in the background, the report is being generated. Then when the report is done being generated/rendered, I need the animated gif and wait message to go away and have the PDF report displayed. I hope this makes sense. Would you be able to provide some suggestions/help with this situation? Here's some code snippets from my second page that is generating, rendering, and displaying the report. (Nothing in the markup for the page.) <html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]" > <head runat="server"> <title>Generated Report</title> <link href="../CSS/ReportsStyleSheet.css" rel="Stylesheet" type="text/css" /> </head> <body> <form id="formRenderReport" runat="server"> <div> </div> </form> </body> </html> (The code-behind...) public partial class Pages_RenderReport : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { AddOnPreRenderCompleteAsync(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation)); } } private System.IAsyncResult BeginAsyncOperation(object sender, EventArgs e, AsyncCallback cb, object state) { // ... // Connect to Reporting Services ReportingExecution.ReportExecutionService rs = new ReportingExecution.ReportExecutionService(); rs.Credentials = System.Net.CredentialCache.DefaultCredentials; // Local Reporting Services variables byte[] result = null; string format = "PDF"; string format = outputformat; string historyID = null; string devInfo = null; string encoding; string mimeType; string extension; ReportingExecution.Warning[] warnings = null; string[] streamIDs = null; // ... try { // Set all the Reporting Services variables and parameters and render the report ReportingExecution.ExecutionInfo execInfo = new ReportingExecution.ExecutionInfo(); ReportingExecution.ExecutionHeader execHeader = new ReportingExecution.ExecutionHeader(); rs.ExecutionHeaderValue = execHeader; execInfo = rs.LoadReport(reportPath1, historyID); rs.SetExecutionParameters(parameters, "en-us"); System.String SessionId = rs.ExecutionHeaderValue.ExecutionID; result = rs.Render(format, devInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs); execInfo = rs.GetExecutionInfo(); // Force the render out of the report to the browser Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AppendHeader("content-length", result.Length.ToString()); switch (outputformat) { case "EXCEL": Response.ContentType = "application/vnd.ms-excel"; // Seems to work break; case "MHTML": Response.ContentType = "message/rfc822"; break; case "PDF": Response.ContentType = "application/pdf"; break; default: Response.ContentType = "application/pdf"; break; } Response.BinaryWrite(result); Response.Flush(); Response.Close(); Response.End(); } catch (System.Exception ex) { // An exception occurred while trying to generate and render the report } // Just needed to get a IAsyncResult to return System.Net.WebRequest hwr = System.Net.WebRequest.Create("[URL]http://localhost/[/URL]"); return hwr.BeginGetResponse(cb, state); } private void EndAsyncOperation(System.IAsyncResult ar) { // } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
How to display page while long-running process executing?
Top