Thuộc tính bộ đệm ASP


❮ Tham chiếu đối tượng phản hồi hoàn chỉnh

Thuộc tính Buffer chỉ định có nên đệm đầu ra hay không. Khi đầu ra được lưu vào bộ đệm, máy chủ sẽ giữ lại phản hồi cho trình duyệt cho đến khi tất cả các tập lệnh máy chủ đã được xử lý hoặc cho đến khi tập lệnh gọi phương thức Flush hoặc End.

Lưu ý: Nếu thuộc tính này được đặt, thuộc tính này phải ở trước thẻ <html> trong tệp .asp

Cú pháp

response.Buffer[=flag]

Parameter Description
flag A boolean value that specifies whether to buffer the page output or not.

False indicates no buffering. The server will send the output as it is processed. False is default for IIS version 4.0 (and earlier). Default for IIS version 5.0 (and later) is true.

True indicates buffering. The server will not send output until all of the scripts on the page have been processed, or until the Flush or End method has been called.

Các ví dụ

ví dụ 1

Trong ví dụ này, sẽ không có đầu ra nào được gửi đến trình duyệt trước khi kết thúc vòng lặp. Nếu bộ đệm được đặt thành Sai, thì nó sẽ ghi một dòng vào trình duyệt mỗi khi đi qua vòng lặp.

<%response.Buffer=true%>
<html>
<body>
<%
for i=1 to 100
  response.write(i & "<br>")
next
%>
</body>
</html>

Ví dụ 2

<%response.Buffer=true%>
<html>
<body>
<p>I write some text, but I will control when
the text will be sent to the browser.</p>
<p>The text is not sent yet. I hold it back!</p>
<p>OK, let it go!</p>
<%response.Flush%>
</body>
</html>

Ví dụ 3

<%response.Buffer=true%>
<html>
<body>
<p>This is some text I want to send to the user.</p>
<p>No, I changed my mind. I want to clear the text.</p>
<%response.Clear%>
</body>
</html>

❮ Tham chiếu đối tượng phản hồi hoàn chỉnh