How can i get the attribute value of HtmlGenericControl?

Anyname Donotcare picture Anyname Donotcare · Feb 29, 2012 · Viewed 8.8k times · Source

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).

Answer

Oleks picture Oleks · Feb 29, 2012

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";