Tip:
Highlight text to annotate it
X
In this section we'll take a look at some of the members of the HTML controls. I'll
be using the HtmlGenericControl as an example, but the methods and fields are almost the
same for all HTML controls. This is because all of them inherit directly from the Control
class. The only difference between them is the properties relating to the elements specific
attributes. And since the generic control doesn't correspond to any special element
it has no such properties.
To get started we'll set the control to represent the div element and add it to the form. The
first useful property to know about is InnerText, to add text inside an element. A similar field
is InnerHtml, to add HTML in the element instead of just text. Notice that these two will overwrite
each other. Another property that's good to know about is Visible, which can be set to
false to hide an element.
Next we have the collections, first off Attributes to change the attributes of the element. Similarly
there's the style collection to change the CSS style of the element. And as we've already
seen the Controls collection can be used to change the elements inside of this element.
Note that since HTML pages are organized as a tree we can navigate through the child controls
using this collection. For example, to get the first child element of the form control
we could access the collection just like an array. There's also the Parent property to
get the parent of this control.