Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 242
Anyname Donotcare Avatar asked Feb 29 '12 08:02

Anyname Donotcare


2 Answers

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";
like image 178
Oleks Avatar answered Nov 09 '22 20:11

Oleks


The Attributes property is name value collection. So you can do string tempstr = inner_li.Attributes["style"].

See the msdn doc.

like image 2
Candide Avatar answered Nov 09 '22 20:11

Candide