We're programming a web application using ASP.NET (1.1 Framework). I've been looking around for some time now for a solution to display a "please wait" message to the user while I run a rather complicated SQL query in the background (it takes up to 30 or more
seconds to run every time, a little too long for your normal web page). I've seen lots of proposed solutions that involve using JavaScript or DHTML to display a "DIV" at regular intervals, but in my case these don't seem to apply. I'm using a version of the
IBuySpy Portal, which is basically a table that instantiates controls within its cells (one or more for each section, left bar, content, right bar, etc.). I have a control I wrote that reads from and writes to a SQL database. Everything is pretty quick except
for the query I mentioned above, which again can take as long as 30 or more seconds depending on the result set. Because of this I'd like to put up a message saying the query is running, then actually display the results when it is done. I've been reading
about Response.Flush and gave it a try, but it does not seem to work. I think the issue here is that fact that the portal is one big table, and that the control (and its code-behind that does flush and the SQL querying) is contained within the table. Because
of this, the web page does not encounter the final closing tag until the control is done its processing and I've read that Response.Flush may not work when called from within a table. Here is a snippet from the code I’m running; MergeChanges() is called directly
from Page_Load within the ASCX control and is the routine that runs the time-consuming SQL query: =====================================================
Private Sub MergeChanges() ' Refresh display so the user knows we're working 'Response.Buffer = False Response.Write("
Please wait while we load your file
" _ + "(this may take as many as 30 seconds to complete).
" _ + "Thank you for your patience.
") Response.Flush() Dim dsChanged As New DataSet() Dim SQLDataAdapter1 As New SqlDataAdapter() . . .
===================================================== I tried this code with and without the “Response.Buffer = False” line and it still works the same way: the “Please wait” message displays along with the rest of the page, but only when the SQL query
and other code-behind code finishes and not a moment before. I would basically like a way to display something to the user that says "trust us, we're working and will display your results ASAP" while the query runs (kind of like the Expedia.com search method).
Even a separate smaller browser window might be fine, though I'm leery about that due to popup killers. Any suggestions? Thank you! Best Regards, Erik
It is possible that it is not displaying the text due to the fact that the content is nested in a table. The browser will not render anything until it has closed out the table, no matter what setting you are using for the output cache. If the running of that
query is holding up the creation of any html on your page, it could be causing the problem you are experiencing. Since the Portal houses everything in nested tables, perhaps you could use an intermediate page to display a friendly message. Once the query is
done, slap the data into a cache object, send the user to the results display page, and load the data from the cache.
Thanks for the reply, WunderKinder. Good suggestion. Since my post I found a way to do this, though there is a small issue remaining that we may be able to live with. The solution is admittedly arcane, but here's what I came up with: 1. I wrapped some ASP code
around the tag of the parent page (the main page of the portal that instantiates all the controls). This code checks to see if a boolean session variable is equal to true or not; if true, it adds an "onload parameter to the tag that effectively makes the page
reload itself with an added querystring parameter: leftmargin=0 bottommargin=0 rightmargin=0 topmargin=0 marginheight=0 marginwidth=0> . . . .
When using the areas of the portal that don't have long SQL queries, the pages will load just fine without the "onload" addition. 2. Within the control that the makes the long SQL call, I put code in the Page_Load event to set the boolean and check for
the querystring parameter: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then ' Possible first time into page ' Check for existence of FT or "First Time" querystring parameter
so we ' know whether or not we already displayed the Please Wait message If Request.QueryString.Item("FT") = "1" Then ' We're coming back after having hit the page the very first time to ' display "Please Wait", so go ahead and make the long SQL call ' ---
code here to make long SQL call --- Session("FirstTime") = False Else ' This is really the first time into the page; set variable so ' DesktopDefault.aspx adds JavaScript code to re-load page ' and display "Please Wait" message Session("FirstTime") = True
End If End If So, basically, here's what happens: 1. When the control that does the long SQL call is loaded into the main portal page, neither the "FirstTime" session variable nor the "FT" querystring parameter exist. 2. The Page_Load event sets the
FirstTime session variable to TRUE. 3. The server-side code wrapped around the tag sets the OnLoad event to reload the page with the added querystring parameter. The initial view of the page contains the "Please Wait" message on a panel within the control
that is visible, whereas a couple other panels within the control are kept hidden. 4. On page reload, the Page_Load event runs the code including the long SQL command since FirstTime has been set to TRUE. 5. When the code comes back, the FirstTime variable
is set to FALSE and the panels are set such that the Please Wait panel is hidden and another panel that displays the results is displayed. 6. On page re-load from there, FirstTime remains false so there is no further re-load (I only need to make this long
SQL call once per "session"). 7. If the user navigates away from this page with the control on it and back, the same steps above happen, which is OK. The small issue is this: within the "Please Wait" message I have an animated GIF that helps indicate that
things are in process, but the animation never works. I think it's related to the fact that I'm using the page's onLoad event. Perhaps animated GIFs only start animating when the page is completed loaded and all tag events are completed? Thanks again for your
help. Erik
None
0 Points
11 Posts
Response.Flush within ASCX not working with Portal application
Oct 08, 2003 10:20 AM|ESBertrand|LINK
Private Sub MergeChanges() ' Refresh display so the user knows we're working 'Response.Buffer = False Response.Write("
===================================================== I tried this code with and without the “Response.Buffer = False” line and it still works the same way: the “Please wait” message displays along with the rest of the page, but only when the SQL query and other code-behind code finishes and not a moment before. I would basically like a way to display something to the user that says "trust us, we're working and will display your results ASAP" while the query runs (kind of like the Expedia.com search method). Even a separate smaller browser window might be fine, though I'm leery about that due to popup killers. Any suggestions? Thank you! Best Regards, Erik

") Response.Flush() Dim dsChanged As New DataSet() Dim SQLDataAdapter1 As New SqlDataAdapter() . . .Please wait while we load your file
" _ + "(this may take as many as 30 seconds to complete).
" _ + "Thank you for your patience.
Member
160 Points
980 Posts
Re: Response.Flush within ASCX not working with Portal application
Oct 08, 2003 05:08 PM|wunderkinder|LINK
None
0 Points
11 Posts
Re: Response.Flush within ASCX not working with Portal application
Oct 10, 2003 09:41 AM|ESBertrand|LINK
leftmargin=0 bottommargin=0 rightmargin=0 topmargin=0 marginheight=0 marginwidth=0> . . . .
When using the areas of the portal that don't have long SQL queries, the pages will load just fine without the "onload" addition. 2. Within the control that the makes the long SQL call, I put code in the Page_Load event to set the boolean and check for the querystring parameter:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then ' Possible first time into page ' Check for existence of FT or "First Time" querystring parameter so we ' know whether or not we already displayed the Please Wait message If Request.QueryString.Item("FT") = "1" Then ' We're coming back after having hit the page the very first time to ' display "Please Wait", so go ahead and make the long SQL call ' --- code here to make long SQL call --- Session("FirstTime") = False Else ' This is really the first time into the page; set variable so ' DesktopDefault.aspx adds JavaScript code to re-load page ' and display "Please Wait" message Session("FirstTime") = True End If End If
So, basically, here's what happens: 1. When the control that does the long SQL call is loaded into the main portal page, neither the "FirstTime" session variable nor the "FT" querystring parameter exist. 2. The Page_Load event sets the FirstTime session variable to TRUE. 3. The server-side code wrapped around the tag sets the OnLoad event to reload the page with the added querystring parameter. The initial view of the page contains the "Please Wait" message on a panel within the control that is visible, whereas a couple other panels within the control are kept hidden. 4. On page reload, the Page_Load event runs the code including the long SQL command since FirstTime has been set to TRUE. 5. When the code comes back, the FirstTime variable is set to FALSE and the panels are set such that the Please Wait panel is hidden and another panel that displays the results is displayed. 6. On page re-load from there, FirstTime remains false so there is no further re-load (I only need to make this long SQL call once per "session"). 7. If the user navigates away from this page with the control on it and back, the same steps above happen, which is OK. The small issue is this: within the "Please Wait" message I have an animated GIF that helps indicate that things are in process, but the animation never works. I think it's related to the fact that I'm using the page's onLoad event. Perhaps animated GIFs only start animating when the page is completed loaded and all tag events are completed? Thanks again for your help. Erik