Buffering the output of multiple controls

G

Guest

Hi

I have a placeholder that has multiple controls that need to be loaded and
rendered to the user based on some user selections. I have to loop through
the choices that the user makes and then load the controls. I am doing this
in the protected override void Render(HtmlTextWriter writer) method.
protected override void Render(HtmlTextWriter writer)
{
foreach (Selection in UsersSelection)
{
switch(Selection)
{
case "Selection 1":
UserControl1 uc1 = Page.LoadControl("Control to be loaded") as UserControl1;
//Set user control properties
Panel.Control.Add(uc1);
case "Selection 2":
UserControl1 uc2 = Page.LoadControl("Control to be loaded") as UserControl1;
//Set user control properties
Panel.Control.Add(uc2);
case "Selection 3":
UserControl1 uc3 = Page.LoadControl("Control to be loaded") as UserControl1;
//Set user control properties
Panel.Control.Add(uc3);
:
:
}
}
base.Render(writer);
}
But I want the page to be displayed as soon as the data from one control has
been obtained. Is there any way to do this ? I tried setting the
Response.Buffer to false and then flushing the results. But what happens is
that all the controls are looped through and then the entire data is shown on
the page at the same time which causes the page to be blank for a some time.

Thanks a lot in advance for any help.
 
B

bruce barker

you will need to take over the render logic yourself, rather then calling
base.Render(). this way you can render and flush each user control.

notes:

1) if your markup is complex, the browser may not render it anyway until get
gets the whole page.
2) if site has high volume you may runout of asp.net threads with this
approach, and your users get a server busy.


-- bruce (sqlwork.com)
 
G

Guest

I had the same issue and I tried to do the render logic but it still does not
flush out the results. Borrowing from the posted code this is what I did

protected override void Render(HtmlTextWriter writer)
{
foreach (Selection in UsersSelection)
{
switch(Selection)
{
case "Selection 1":
UserControl1 uc1 = Page.LoadControl("Control to be loaded") as UserControl1;
//Set user control properties
Panel.Control.Add(uc1);
case "Selection 2":
UserControl1 uc2 = Page.LoadControl("Control to be loaded") as UserControl1;
//Set user control properties
Panel.Control.Add(uc2);
case "Selection 3":
UserControl1 uc3 = Page.LoadControl("Control to be loaded") as UserControl1;
//Set user control properties
Panel.Control.Add(uc3);
:
:
}
Panel.RenderControl(writer);
writer.Flush();
}
}

But that also does not seem to help at all. The page remains blank till the
entire results are returned, I expected to see some incremental flushing of
the results on to the screen so that the blank page does not exist. Any
ideas ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top