How can I get the value of the HtmlGenericControl attribute?

I create an HtmlGenericControl as follows:

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

How can I get the value of this attribute ( style ).

+4
source share
3 answers

You can do this with an indexer:

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

Just note: when working with styles, it is better to use the HtmlControl.Style property:

 inner_li.Style[HtmlTextWriterStyle.ListStyleType] = "none"; 
+8
source

The Attributes property is the collection of value values. That way you can do string tempstr = inner_li.Attributes["style"] .

See msdn doc .

+2
source

You can get the value using the following statement

 string myvalue= inner_li.Attributes["style"]; 
+1
source

Source: https://habr.com/ru/post/1398973/


All Articles