편집

다음을 통해 공유


HtmlTextWriter.ExitStyle Method

Definition

Writes the closing tag of a markup element to end the specified layout and character formatting.

Overloads

ExitStyle(Style)

Writes the closing tag of a <span> element to end the specified layout and character formatting.

ExitStyle(Style, HtmlTextWriterTag)

Writes the closing tag of the specified markup element to end the specified layout and character formatting.

ExitStyle(Style)

Writes the closing tag of a <span> element to end the specified layout and character formatting.

public:
 virtual void ExitStyle(System::Web::UI::WebControls::Style ^ style);
public virtual void ExitStyle (System.Web.UI.WebControls.Style style);
abstract member ExitStyle : System.Web.UI.WebControls.Style -> unit
override this.ExitStyle : System.Web.UI.WebControls.Style -> unit
Public Overridable Sub ExitStyle (style As Style)

Parameters

style
Style

A Style that specifies the layout and formatting to close.

Examples

The following code example demonstrates how to use a custom class named TextSample, derived from the WebControl class, that uses the EnterStyle method to apply a ForeColor style to a string of text.

The EnterStyle method renders the HTML <span style="color:Navy;">. The ExitStyle method call closes the <span> element after the text has been rendered.

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Imports System.Drawing

' Create a custom class, named TextSample, that renders
' its Text property with styles applied by the
' EnterStyle and ExitStyle methods. 
Namespace AspNet.Samples

    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class TextSample
        Inherits Control

        ' Create an instance of the Style class.
        Private textStyle As Style = New Style()
        Private textMessage As String

        ' Create a Text property.
        Public Property Text() As String
            Get
                Return textMessage
            End Get
            Set(ByVal value As String)
                textMessage = value
            End Set
        End Property


        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            ' Set the value of the Text property.
            textMessage = "Hello, World!"

            ' Set the Style object's ForeColor
            ' property to Navy.
            textStyle.ForeColor = Color.Navy

            ' Render the Text property with the style.
            writer.WriteLine("The text property styled: ")
            writer.EnterStyle(textStyle)
            writer.Write(Text)
            writer.ExitStyle(textStyle)

            ' Use the WriteBreak method twice to render
            ' an empty line between the lines of rendered text.
            writer.WriteBreak()
            writer.WriteBreak()

            ' Render the Text property without the style.
            writer.WriteLine("The Text property unstyled: ")
            writer.Write(Text)
        End Sub
    End Class
End Namespace

Remarks

The ExitStyle overload of the ExitStyle(Style) method renders the closing tag of a <span> element after the closing tag of the control, closing the element opened by the corresponding EnterStyle call.

The ExitStyle and EnterStyle methods allow a device adapter or control to create markup that begins and ends a block by using the character formatting of the specified style. Use the same value for style in the EnterStyle method that you use in the corresponding ExitStyle method.

See also

Applies to

ExitStyle(Style, HtmlTextWriterTag)

Writes the closing tag of the specified markup element to end the specified layout and character formatting.

public:
 virtual void ExitStyle(System::Web::UI::WebControls::Style ^ style, System::Web::UI::HtmlTextWriterTag tag);
public virtual void ExitStyle (System.Web.UI.WebControls.Style style, System.Web.UI.HtmlTextWriterTag tag);
abstract member ExitStyle : System.Web.UI.WebControls.Style * System.Web.UI.HtmlTextWriterTag -> unit
override this.ExitStyle : System.Web.UI.WebControls.Style * System.Web.UI.HtmlTextWriterTag -> unit
Public Overridable Sub ExitStyle (style As Style, tag As HtmlTextWriterTag)

Parameters

style
Style

A Style that specifies the layout and formatting to stop applying to the output text.

tag
HtmlTextWriterTag

An HtmlTextWriterTag that specifies the closing tag of the markup element that contained the attributes that applied the specified style. This must match the key passed in the corresponding EnterStyle call.

Examples

The following code example demonstrates how to use a custom class named TextSample, derived from the WebControl class, that uses the EnterStyle method to apply a ForeColor style to a string of text.

The EnterStyle method renders the HTML <span style="color:Navy;">. The ExitStyle method call closes the <span> element after the text has been rendered.

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Imports System.Drawing

' Create a custom class, named TextSample, that renders
' its Text property with styles applied by the
' EnterStyle and ExitStyle methods. 
Namespace AspNet.Samples

    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class TextSample
        Inherits Control

        ' Create an instance of the Style class.
        Private textStyle As Style = New Style()
        Private textMessage As String

        ' Create a Text property.
        Public Property Text() As String
            Get
                Return textMessage
            End Get
            Set(ByVal value As String)
                textMessage = value
            End Set
        End Property


        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            ' Set the value of the Text property.
            textMessage = "Hello, World!"

            ' Set the Style object's ForeColor
            ' property to Navy.
            textStyle.ForeColor = Color.Navy

            ' Render the Text property with the style.
            writer.WriteLine("The text property styled: ")
            writer.EnterStyle(textStyle)
            writer.Write(Text)
            writer.ExitStyle(textStyle)

            ' Use the WriteBreak method twice to render
            ' an empty line between the lines of rendered text.
            writer.WriteBreak()
            writer.WriteBreak()

            ' Render the Text property without the style.
            writer.WriteLine("The Text property unstyled: ")
            writer.Write(Text)
        End Sub
    End Class
End Namespace

Remarks

The ExitStyle overload of the ExitStyle(Style, HtmlTextWriterTag) method renders the closing tag of the element that is specified by tag after the closing tag of the control, closing the element that was opened by the corresponding EnterStyle(Style, HtmlTextWriterTag) method call.

The ExitStyle and EnterStyle methods allow a device adapter or control to create markup that begins and ends a block by using the character formatting of the specified style. Use the same value for style in the EnterStyle method that you use in the corresponding ExitStyle method.

See also

Applies to