Search code examples
c#asp.nethtmlhtmlgenericcontrol

How can i get the attribute value of HtmlGenericControl?


I create HtmlGenericControl like this :

HtmlGenericControl inner_li = new HtmlGenericControl("li");
inner_li.Attributes.Add("style", "list-style-type: none");

How can i get the value of this attribue(style).


Solution

  • You can do it using indexer:

    var style = inner_li.Attributes["style"];
    

    Just a side note: when dealing with styles it's better to use HtmlControl.Style property:

    inner_li.Style[HtmlTextWriterStyle.ListStyleType] = "none";