alain123
asked on
Response.Flush();
why when i run or step trough this code, the html added to the page does not show at the moment of Thread.Sleep? thank you.
placeholder.Controls.Clear ();
string HTML = "";
HTML = "<table><tr><td>test</td>< /tr></tabl e>";
Control objControl = this.Page.ParseControl(HTM L);
this.placeholder.Controls. Add(objCon trol);
//Response.Clear();
Response.Buffer= true;
Response.Flush();
this.placeholder.Visible = true;
Thread.Sleep(15000);
placeholder.Controls.Clear
string HTML = "";
HTML = "<table><tr><td>test</td><
Control objControl = this.Page.ParseControl(HTM
this.placeholder.Controls.
//Response.Clear();
Response.Buffer= true;
Response.Flush();
this.placeholder.Visible = true;
Thread.Sleep(15000);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Then you are nto going to see any HTML in the output because none has been generated. yet.
Why are you flushing in OnInit? At that stage you have pretty much nothing to flush.
Why are you flushing in OnInit? At that stage you have pretty much nothing to flush.
ASKER
no I'm not flushing inside OnInit().. but After.. I'm flushing inside a Button_Onclick() event that it's called after OnInit()... and
"Then you are nto going to see any HTML in the output because none has been generated. yet" ..I'm adding the html to the control .. i think it should be there, unless i'm not doind some kind of refreshing..
HTML = "<table><tr><td>test</td>< /tr></tabl e>";
Control objControl = this.Page.ParseControl(HTM L);
this.placeholder.Controls. Add(objCon trol);
"Then you are nto going to see any HTML in the output because none has been generated. yet" ..I'm adding the html to the control .. i think it should be there, unless i'm not doind some kind of refreshing..
HTML = "<table><tr><td>test</td><
Control objControl = this.Page.ParseControl(HTM
this.placeholder.Controls.
Sorry alain, I've had very littel exposure to the finer points of using controls so I can't help.
ASKER
Thank you mon, for your help, i appreaciate it.
Before the render method no html will be written to the output stream therefore Response.Flush() does not change anything. Response.Buffer should be changed in the beginning of the pages lifecycle so that either all contents or nothing is buffered.
Place this code in OnPreRender:
placeholder.Controls.Clear ();
string HTML = "";
HTML = "<table><tr><td>test</td>< /tr></tabl e>";
Control objControl = this.Page.ParseControl(HTM L);
this.placeholder.Controls. Add(objCon trol);
Response.Buffer= true;
Place this code in the overriden Render method:
this.placeholder.Visible = true;
Response.Flush();
Thread.Sleep(15000);
placeholder.Controls.Clear
string HTML = "";
HTML = "<table><tr><td>test</td><
Control objControl = this.Page.ParseControl(HTM
this.placeholder.Controls.
Response.Buffer= true;
Place this code in the overriden Render method:
this.placeholder.Visible = true;
Response.Flush();
Thread.Sleep(15000);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this works and you see the page 'filling up", it seams the Reponse object does not recognise the setting of Buffer to true until it has flushed the response automatically, I just pushed 300 spaces onto the stream as a test and it works.
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Buffer= true;
// Response.Write( "0123456789012345678901234 5678901234 5678901234 5678901234 5678901234 5678901234 5678901234 5678901234 56789<br>" );
Response.Write( " " );
Response.Write( " " );
Response.Write( " " );
Response.Flush();
Response.Write("test2");
for( int i = 0 ; i < 100 ; i ++ )
{
Response.Write( string.Format("Message {0}<br>" , i ) ) ;
Response.Flush();
System.Threading.Thread.Sl eep(100);
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Buffer= true;
// Response.Write( "0123456789012345678901234
Response.Write( " " );
Response.Write( " " );
Response.Write( " " );
Response.Flush();
Response.Write("test2");
for( int i = 0 ; i < 100 ; i ++ )
{
Response.Write( string.Format("Message {0}<br>" , i ) ) ;
Response.Flush();
System.Threading.Thread.Sl
}
}
ASKER