The Response.Write () method is very common, and is common, which is to output a string to HTTP outputs. Its output is located at the top of the page, commonly used to display some page message boxes and other logic.
In general, the content that is output through Response.Write during the entire life cycle of the page will be output to the client side at the end of the document flow with the page. But with the help of Response.Flush, we can realize the dynamic interaction of the front and rear stations in the process.
The Response.Flush method forces the content in the buffer to be output to the client side without waiting for the end of the life cycle. Through an example to deepen understanding, the instance in real-time response to the progress of the background method execution.
Each time the background attempts to update the client progress, will be output by Response.Write A JS script, through JS to update the progress value.
for (int1; i++) { thread.sleep (+); Setprocessvalue (i);}
Private void setprocessvalue (int percent) { new StringBuilder (); Sb. Append ("<script>setprocessbarvalue ('" ") </script >"); HttpContext.Current.Response.Write (sb.) ToString ()); HttpContext.Current.Response.Flush ();}
Running the code, you will see that progress value is incremented incrementally as the method executes. The Response.Flush call ensures that the content is output to the client in a timely manner whenever execution occurs.
Remove all Response.Flush from the code and run the code. The result changes, and progress value is changed from 0 to 100 only once the page has been loaded completely. Sample code
Use Response.Write to achieve front and back interaction in the life cycle of a page