Answer 1)
Generally we will end up with exceptions when we use Response.Flush and redirect the page using Response.Redirect. But same will works fine using Server.Execute.
In general, you can use Response.Flush statement as many times as you want. But you can not send any additional HTTP headers to browser once ASP.NET flushes the content to browser. So sending of HTTP headers should happen before 1st Response.Flush statement.
//Page1.aspx.cs protected void Page_Load(object sender, EventArgs e) { Server.Execute("Page2.aspx"); }
Observer the above code. It’s calling Server.Execute("Page2.aspx") from Page1.aspx Page_Load method.
Meaning of above code is, - Include the page content of Page2.aspx in Page1.aspx,
- And HTTP headers generated by Page2.aspx will be ignored.
The end result will contain the content of Page1.aspx + Page2.aspx.
But whereas Response.Redirect sends HTTP header (“location:” http header) to the browser, so browser will request the new page specified in the “location http header”. But remember the problem with Response.Flush, ASP.NET can not send any HTTP headers once some content already sent to browser. That is the reason Response.Redirect will not work with combination with Response.Flush, but whereas Server.Execute can.
|