This documentation is archived and is not being maintained.

HtmlTextWriter.Flush Method

Clears all buffers for the current HtmlTextWriter and causes any buffered data to be written to the text stream.

[Visual Basic]
Overrides Public Sub Flush()
[C#]
public override void Flush();
[C++]
public: void Flush();
[JScript]
public override function Flush();

Example

[Visual Basic, C#, C++] The following code example calls the Flush method after an HTML Label element has been rendered in an override of the Control.Render method.

[Visual Basic] 
Public Class FirstControl
   Inherits WebControl
   'The message property.
   Private myMessage As String = "Hello"

   'Accessors for the message property.

   Public Overridable Property Message() As [String]
      Get
         Return myMessage
      End Get
      Set(ByVal Value As [String])
         myMessage = Value
      End Set
   End Property


   Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
      'Output the 'label' html tag
      writer.WriteBeginTag("label")
      'Output the space character.
      writer.Write(HtmlTextWriter.SpaceChar)
      'Output the string "style" followed by "=\"".
      writer.Write(("style" + HtmlTextWriter.EqualsDoubleQuoteString))
      'Output the style attribute "font-size".
      writer.Write(("font-size" + HtmlTextWriter.StyleEqualsChar + "12pt"))
      'Output a style attribute separator.
      writer.Write(HtmlTextWriter.SemicolonChar)
      'Output the style attribute "color".
      writer.Write(("color" + HtmlTextWriter.StyleEqualsChar + "fuchsia"))
      'Output the double quote character.
      writer.Write(HtmlTextWriter.DoubleQuoteChar)
      'Output the '>' character.
      writer.Write(HtmlTextWriter.TagRightChar)
      'Output the 'Message' property.
      writer.Write(Message)
      'Output the 'Message' property contents and the time on the server.
      writer.Write(("<br>" + "<font color=""blue"">" + "The time on the server: " + System.DateTime.Now.ToLongTimeString() + "</font>"))
      'Flush the contents of the 'HtmlTextWriter'.
      writer.Flush()
   End Sub 'Render 
End Class 'FirstControl 

[C#] 
public class FirstControl : WebControl
{
    // The message property.
    private String message = "Hello";

    // Accessors for the message property.
    public virtual String Message 
    {
        get {
            return message;
        }
        set {
            message = value;
        }
    }

    protected override void Render(HtmlTextWriter writer) 
    {
        // Output the 'label' html tag.
        writer.WriteBeginTag("label");
        // Output the space character.
        writer.Write(HtmlTextWriter.SpaceChar);
        // Output the string "style" followed by "=\"".
        writer.Write("style" + HtmlTextWriter.EqualsDoubleQuoteString);
        // Output the style attribute "font-size".
        writer.Write("font-size" + HtmlTextWriter.StyleEqualsChar + "12pt");
        // Output a style attribute separator.
        writer.Write(HtmlTextWriter.SemicolonChar);
        // Output the style attribute "color".
        writer.Write("color" + HtmlTextWriter.StyleEqualsChar + "fuchsia");
        // Output the double quote character.
        writer.Write(HtmlTextWriter.DoubleQuoteChar);
        // Output the '>' character.
        writer.Write(HtmlTextWriter.TagRightChar);
        // Output the 'Message' property.
        writer.Write(Message);
        // Output the 'Message' property contents and the time on the server.
        writer.Write("<br>" + "<font color=\"blue\">" +
                     "The time on the server: " +
                     System.DateTime.Now.ToLongTimeString() + 
                     "</font>");
        // Flush the contents of the 'HtmlTextWriter'.
        writer.Flush();
    }
}

[C++] 
public __gc class FirstControl : public WebControl
{
   // The message property.
private:
   String* message;

   // Accessors for the message property.
public:
   __property virtual String* get_Message() {
      return message;
   }
   __property virtual void set_Message( String* value ) {
      message = value;
   }

protected:
   void Render(HtmlTextWriter* writer) 
   {
      // Output the 'label' html tag.
      writer->WriteBeginTag(S"label");
      // Output the space character.
      writer->Write(HtmlTextWriter::SpaceChar);
      // Output the string "style" followed by "=\"".
      writer->Write(S"style{0}", HtmlTextWriter::EqualsDoubleQuoteString);
      // Output the style attribute "font-size".
      writer->Write(S"font-size{0}12pt",__box(HtmlTextWriter::StyleEqualsChar));
      // Output a style attribute separator.
      writer->Write(HtmlTextWriter::SemicolonChar);
      // Output the style attribute "color".
      writer->Write(S"color{0}fuchsia",__box(HtmlTextWriter::StyleEqualsChar));
      // Output the double quote character.
      writer->Write(HtmlTextWriter::DoubleQuoteChar);
      // Output the '>' character.
      writer->Write(HtmlTextWriter::TagRightChar);
      // Output the 'Message' property.
      writer->Write(Message);
      // Output the 'Message' property contents and the time on the server.
      writer->Write(S"<br><font color=\"blue\">The time on the server: {0}</font>",
         System::DateTime::Now.ToLongTimeString() );
      // Flush the contents of the 'HtmlTextWriter'.
      writer->Flush();
   }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HtmlTextWriter Class | HtmlTextWriter Members | System.Web.UI Namespace | TextWriter

Show: