This documentation is archived and is not being maintained.

HtmlTextWriter.Close Method

Closes the current HtmlTextWriter and releases any system resources associated with it.

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

Remarks

This implementation of Close calls the System.IO.TextWriter method, passing a true value.

Following a call to Close, any operations on the HtmlTextWriter may throw exceptions.

You do not need to call this method. The Web Forms infrastructure calls it automatically.

Example

[Visual Basic, C#, C++] The following code example overrides the Control.Dispose method to call the Close and call the Dispose method on a Button control, named myButton. If an Exception is thrown when this version of the Dispose method is called, the control writes a message to the current System.Web.HttpRepsonse object.

[Visual Basic] 
Public Overrides Sub Dispose()
   Try
      Context.Response.Write("Disposing " & ToString())
      ' Perform resource cleanup.
      myTextWriter.Close()
      myButton.Dispose()
   Catch myException As Exception
      Context.Response.Write("Exception occurred: " & myException.Message)
   End Try
End Sub

[C#] 
public override void Dispose()
{
   try
   {
      Context.Response.Write("Disposing " + ToString());
      // Perform resource cleanup.
      myTextWriter.Close();
      myButton.Dispose();
   }
   catch(Exception myException)
   {
      Context.Response.Write("Exception occurred: "+myException.Message);
   }
}

[C++] 
public:
    void Dispose()
    {
        try
        {
            Context->Response->Write(String::Concat(S"Disposing ", ToString()));
            // Perform resource cleanup.
            myTextWriter->Close();
            myButton->Dispose();
        }
        catch(Exception* myException)
        {
            Context->Response->Write(String::Concat(S"Exception occurred: ", myException->Message));
        }
    }

[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: