Render asp.net relay how-and-when html chunks are ready (streaming)

The problem lies in providing huge reports. Basically we have a lot of data that is displayed in html reports (mostly using a relay or gridview). It just so happens that the data started out small and now we have tons of it. There are many such reports already built, so a complete rewrite is not an option. Hell, business doesn't even let us print data. Server memory now fires every time we try to display some reports. So the question is, is it possible to somehow bind the data to the relay and pipe it to the html stream to the browser, how and when the chunks are ready? Thus, we hope not to bring all this data to the application server at once. I think we'll be using a datareader or something to get pieces of data and display them in the browser. Any pointers,links, ideas?

+2


a source to share


3 answers


You have several options, but you cannot use a repeater for this.

ASP.NET does not render the HTML defined in ASPX until it removes the render phase of the page lifecycle . Before that, almost anything can happen to the page (in Page_Init, Page_Load, etc.): It can add or remove controls on the page, can bind data sources, etc. Therefore there is no way to know what to send to the client yet.

One option is to generate a report from the client using AJAX: first load the HTML and then modify it with incremental calls to the server until you use all the report data. This will allow you to rip your reports into whatever size chunks you want, but this can get pretty tricky. (On the other hand, perhaps someone has already created a control to facilitate this.)



Another option is to control your HTML generation and write the entire page manually in your code class (instead of using a pretty, easy-to-read .aspx template). To see this in action, create a completely empty .aspx (other than the declaration @Page

) and put this in your method Page_Load

:

protected void Page_Load(object sender, EventArgs e) 
{
    Response.Write("<html><body><ul>");

    // this could be iterating a data reader
    for(int i=0; i<5; i++) 
    {
        Response.Write("<li>Item " + i.ToString() + "</li>");

        // you might tweak your buffer settings instead of flushing on
        // each write - this is just for demonstration purposes
        Response.Flush();

        // this just dramatizes the fact that it streaming
        // by adding a two-second delay
        System.Threading.Thread.Sleep(2000);
    }
    Response.Write("</ul></body></html>");
}

      

0


a source


It would be an interesting solution for jQuery infinite scrolling.

http://www.infinite-scroll.com/



Since you are not allowed to swap, you can loop through the cast and only then the records are fetched from the database and displayed. One problem will be that you need to dynamically add rows to the GridView using JavaScript.

Think like Google Reader where you browse feeds and then all feeds are loaded.

+2


a source


In such cases, Response.Write is your friend. Unfortunately, you will give up the intricacies of data binding and repeaters. Here is the link http://highscalability.com/plentyoffish-architecture

0


a source







All Articles