HtmlTextWriter.AddStyleAttribute 메서드

정의

태그 스타일 특성을 HtmlTextWriter 개체가 RenderBeginTag 메서드를 이후에 호출하여 만드는 요소의 여는 태그에 추가합니다.

오버로드

AddStyleAttribute(String, String)

지정된 태그 스타일 특성과 특성 값을 RenderBeginTag 메서드를 이후에 호출하여 만들어진 여는 태그에 추가합니다.

AddStyleAttribute(HtmlTextWriterStyle, String)

지정된 HtmlTextWriterStyle 값과 연결된 태그 스타일 특성과 특성 값을 RenderBeginTag 메서드를 이후에 호출하여 만들어진 여는 태그에 추가합니다.

AddStyleAttribute(String, String, HtmlTextWriterStyle)

지정된 태그 스타일 특성과 특성 값을 HtmlTextWriterStyle 열거형 값과 함께 RenderBeginTag 메서드를 이후에 호출하여 만들어진 여는 태그에 추가합니다.

AddStyleAttribute(String, String)

지정된 태그 스타일 특성과 특성 값을 RenderBeginTag 메서드를 이후에 호출하여 만들어진 여는 태그에 추가합니다.

public:
 virtual void AddStyleAttribute(System::String ^ name, System::String ^ value);
public virtual void AddStyleAttribute (string name, string value);
abstract member AddStyleAttribute : string * string -> unit
override this.AddStyleAttribute : string * string -> unit
Public Overridable Sub AddStyleAttribute (name As String, value As String)

매개 변수

name
String

추가할 스타일 특성이 포함된 문자열입니다.

value
String

특성에 할당할 값이 포함된 문자열입니다.

예제

다음 코드 예제에서는 메서드의 오버로드를 RenderBeginTag 사용하여 요소에 AddStyleAttribute(String, String) 특성을 <p> 렌더링 font-size 하고 color 스타일을 지정하는 방법을 보여 있습니다. 이 코드 예제에서는 클래스를 HtmlTextWriter 사용하여 컨트롤의 내용을 렌더링합니다.

// Add style attribute for 'p'(paragraph) element.
writer->AddStyleAttribute( "font-size", "12pt" );
writer->AddStyleAttribute( "color", "fuchsia" );
// Output the 'p' (paragraph) element with the style attributes.
writer->RenderBeginTag( "p" );
// Output the 'Message' property contents and the time on the server.
writer->Write( String::Concat( Message, "<br>",
   "The time on the server: ",
   System::DateTime::Now.ToLongTimeString() ) );

// Close the element.
writer->RenderEndTag();
// Add style attribute for 'p'(paragraph) element.
writer.AddStyleAttribute("font-size", "12pt");
writer.AddStyleAttribute("color", "fuchsia");
// Output the 'p' (paragraph) element with the style attributes.
writer.RenderBeginTag("p");
// Output the 'Message' property contents and the time on the server.
writer.Write(Message + "<br>" +
    "The time on the server: " +
    System.DateTime.Now.ToLongTimeString());

// Close the element.
writer.RenderEndTag();
'Add style attribute for 'p'(paragraph) element.
writer.AddStyleAttribute("font-size", "12pt")
writer.AddStyleAttribute("color", "fuchsia")

'Output the 'p' (paragraph) element with the style attributes.
writer.RenderBeginTag("p")

'Output the 'Message' property contents and the time on the server.
writer.Write((Message & "<br>" & "The time on the server: " & _
   System.DateTime.Now.ToLongTimeString()))

' Close the element.
writer.RenderEndTag()

설명

스타일이 AddStyleAttribute 열거형의 AddStyleAttribute(String, String) 멤버가 아니거나 런타임까지 알려지지 않은 경우 메서드의 HtmlTextWriterStyle 오버로드를 사용합니다.

클래스는 HtmlTextWriter 렌더링되는 태그 요소에 대한 스타일 목록을 유지 관리합니다. 메서드가 RenderBeginTag 호출되면 메서드에 의해 AddStyleAttribute 추가된 모든 스타일이 요소의 여는 태그에 렌더링됩니다. 그런 다음 스타일 목록이 지워집니다.

태그 요소를 렌더링하기 위한 코딩 패턴은 다음과 같습니다.

  • 메서드를 AddStyleAttribute 사용하여 요소에 스타일 특성을 추가합니다.

  • RenderBeginTag 메서드를 사용하세요.

  • 필요에 따라 다른 메서드를 사용하여 요소 여는 태그와 닫는 태그 사이에 있는 콘텐츠를 렌더링합니다.

  • RenderEndTag 메서드를 사용하세요.

추가 정보

적용 대상

AddStyleAttribute(HtmlTextWriterStyle, String)

지정된 HtmlTextWriterStyle 값과 연결된 태그 스타일 특성과 특성 값을 RenderBeginTag 메서드를 이후에 호출하여 만들어진 여는 태그에 추가합니다.

public:
 virtual void AddStyleAttribute(System::Web::UI::HtmlTextWriterStyle key, System::String ^ value);
public virtual void AddStyleAttribute (System.Web.UI.HtmlTextWriterStyle key, string value);
abstract member AddStyleAttribute : System.Web.UI.HtmlTextWriterStyle * string -> unit
override this.AddStyleAttribute : System.Web.UI.HtmlTextWriterStyle * string -> unit
Public Overridable Sub AddStyleAttribute (key As HtmlTextWriterStyle, value As String)

매개 변수

key
HtmlTextWriterStyle

출력 스트림에 추가할 스타일 특성을 나타내는 HtmlTextWriterStyle입니다.

value
String

특성에 할당할 값이 포함된 문자열입니다.

예제

다음 코드 예제에서는 클래스에서 HtmlTextWriter 파생 된 클래스에서 메서드 재정의의 RenderBeginTag 일부를 사용 하는 방법을 보여 줍니다. 코드는 요소가 렌더링되고 있는지 여부를 <Label> 확인합니다. 이 경우 요소에 IsStyleAttributeDefined 대해 스타일 특성이 정의되었는지 여부를 Color 확인하기 위해 메서드가 <Label> 호출됩니다. 특성이 Color 정의되지 않은 경우 코드는 메서드의 AddStyleAttribute 이 오버로드를 호출하여 특성을 스타일 특성에 추가 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)
{
    // 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

설명

스타일이 AddStyleAttribute 열거형의 AddStyleAttribute(HtmlTextWriterStyle, String) 멤버이고 런타임 전에 알려진 경우 메서드의 HtmlTextWriterStyle 오버로드를 사용합니다.

클래스는 HtmlTextWriter 렌더링되는 태그 요소에 대한 스타일 목록을 유지 관리합니다. 메서드가 RenderBeginTag 호출되면 메서드에 의해 AddStyleAttribute 추가된 모든 스타일이 요소의 여는 태그에 렌더링됩니다. 그런 다음 스타일 목록이 지워집니다.

태그 요소를 렌더링하기 위한 코딩 패턴은 다음과 같습니다.

  • 메서드를 AddStyleAttribute 사용하여 요소에 스타일 특성을 추가합니다.

  • RenderBeginTag 메서드를 사용하세요.

  • 필요에 따라 다른 메서드를 사용하여 요소 여는 태그와 닫는 태그 사이에 있는 콘텐츠를 렌더링합니다.

  • RenderEndTag 메서드를 사용하세요.

추가 정보

적용 대상

AddStyleAttribute(String, String, HtmlTextWriterStyle)

지정된 태그 스타일 특성과 특성 값을 HtmlTextWriterStyle 열거형 값과 함께 RenderBeginTag 메서드를 이후에 호출하여 만들어진 여는 태그에 추가합니다.

protected:
 virtual void AddStyleAttribute(System::String ^ name, System::String ^ value, System::Web::UI::HtmlTextWriterStyle key);
protected virtual void AddStyleAttribute (string name, string value, System.Web.UI.HtmlTextWriterStyle key);
abstract member AddStyleAttribute : string * string * System.Web.UI.HtmlTextWriterStyle -> unit
override this.AddStyleAttribute : string * string * System.Web.UI.HtmlTextWriterStyle -> unit
Protected Overridable Sub AddStyleAttribute (name As String, value As String, key As HtmlTextWriterStyle)

매개 변수

name
String

추가할 스타일 특성이 포함된 문자열입니다.

value
String

특성에 할당할 값이 포함된 문자열입니다.

key
HtmlTextWriterStyle

추가할 스타일 특성을 나타내는 HtmlTextWriterStyle입니다.

설명

클래스에서 상속하는 AddStyleAttribute AddStyleAttribute(String, String, HtmlTextWriterStyle) 경우에만 메서드의 오버로드를 HtmlTextWriter 사용합니다. 이를 통해 특성에 대한 새 name 쌍과 value 쌍을 HtmlTextWriterStyle 만들 수 있습니다.

추가 정보

적용 대상