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 получения имени атрибута стиля.

Возвращаемое значение

Имя атрибута стиля, связанное со значением HtmlTextWriterStyle перечисления, указанным в styleKey.

Примеры

В следующем примере кода показано, как проверить, выполняется ли <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

Комментарии

Если styleKey недопустимый HtmlTextWriterStyle объект, GetStyleName метод возвращает пустую строку ("").

Применяется к

См. также раздел