Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Output Stream + Progrss Meter

Status
Not open for further replies.

Smeat

Programmer
Mar 27, 2004
193
GB
We have been trying to render a progress meter using Ajax but have failed due to a conflict with Component Art controls so I now need to look at an alternative solution.

What I would like to do is render an animated gif down to the client before any processing begins. The following is a sample test page:

Code:
public partial class Page2 : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        RenderProgressMeter();

        if (!Page.IsPostBack)
        {
            //Simulate a long running process.
            System.Threading.Thread.Sleep(3000);
        }

        lblMessage.Text = "Page 2";
        
        base.OnInit(e);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }

    private void RenderProgressMeter()
    {
        string output = "<img src='" + ResolveUrl("Images/loadingstrip.gif") + "' alt='Progress Meter' />";
        
        System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
        byte[] outputBytes = encoder.GetBytes(output);
        Response.OutputStream.Write(outputBytes, 0, outputBytes.Length);
        Response.OutputStream.Flush();
    }
}

Unfortunately this doesn't render the image until the page has finished processing. Any ideas how I can force the browser to download and render this image whilst waiting for the server to finish processing.

TIA

Smeat
 
all processing is done on the server, before sending the request. to have any sort of progress animation while a request is processing requires an ajax request.

Matt Berseth has blogged alot about web guis and ajax. most recently he created a realtime progress upload bar. there may be some info on his site which may guide you.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks jmeckley, I'll check out that link.

I've never tried writing directly to the response stream before but I'm under the impression you can send content down to the client before the server has finished processing, isn't that what the

Code:
Response.OutputStream.Flush();
is used for?

Smeat
 
I know that Flushing a file stream will write the current buffer to disk and clear the buffer. To assume the same of an httpresponse seems reasonable. there may be other processes in the pipeline, or on the browser that prevent this. I'm not 100% sure.

from an archetcutral(sp) viewpoint I would say this is a poor design because there is tight coupling between the rendering and the transmission.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top