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 метод возвращает пустую строку ("").

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

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