HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) 메서드

정의

지정된 HtmlTextWriterStyle 열거형 값과 관련된 태그 스타일 특성 이름을 가져옵니다.

protected:
 System::String ^ GetStyleName(System::Web::UI::HtmlTextWriterStyle styleKey);
protected string GetStyleName (System.Web.UI.HtmlTextWriterStyle styleKey);
member this.GetStyleName : System.Web.UI.HtmlTextWriterStyle -> string
Protected Function GetStyleName (styleKey As HtmlTextWriterStyle) As String

매개 변수

styleKey
HtmlTextWriterStyle

태그 특성 이름을 가져올 HtmlTextWriterStyle입니다.

반환

String

styleKey에 지정된 HtmlTextWriterStyle 열거형 값과 관련된 스타일 특성 이름입니다.

예제

다음 코드 예제에서는 요소가 렌더링되는지 여부를 <label> 확인하는 방법을 보여 있습니다. 이 경우 요소에 Color 스타일 특성이 정의되었는지 여부를 확인합니다. 특성이 정의 AddStyleAttribute 되지 않은 경우 메서드가 호출되고 GetStyleName 메서드가 열거형 멤버를 문자열 표현으로 변환 Color 하여 메서드에 AddStyleAttribute 전달합니다.

// If the markup element being rendered is a Label,
// render the opening tag of a <Font> element before it.
if ( tagKey == HtmlTextWriterTag::Label )
{
   
   // Check whether a Color style attribute is
   // included on the Label. If not, use the
   // AddStyleAttribute and GetStyleName methods to add one
   // and set its value to red.
   if (  !IsStyleAttributeDefined( HtmlTextWriterStyle::Color ) )
   {
      AddStyleAttribute( GetStyleName( HtmlTextWriterStyle::Color ), "red" );
   }
// If the markup element being rendered is a Label,
// render the opening tag of a Font element before it.
if (tagKey == HtmlTextWriterTag.Label)
{
    // Check whether a Color style attribute is 
    // included on the Label. If not, use the
    // AddStyleAttribute and GetStyleName methods to add one
    // and set its value to red.
    if (!IsStyleAttributeDefined(HtmlTextWriterStyle.Color))
    {
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red");
    }
' If the markup element being rendered is a Label,
' render the opening tag of a Font element before it.
If tagKey = HtmlTextWriterTag.Label Then
    ' Check whether a Color style attribute is 
    ' included on the Label. If not, use the
    ' AddStyleAttribute and GetStyleName methods to add one
    ' and set its value to red.
    If Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red")
    End If

설명

유효한 HtmlTextWriterStyle 개체가 아니면 styleKey 메서드는 GetStyleName 빈 문자열("")을 반환합니다.

적용 대상

추가 정보