Class UIObject
Abstract class to represent a HTML object.
public abstract class UIObject
- Inheritance
-
UIObject
- Derived
- Inherited Members
Examples
The following is an example of how
the UIObject
can be used to abstract
a HTML Link.
public class Hyperlink : UIObject
{
private string _caption;
public Hyperlink(string caption, string url)
: base("a") // HTML object
{
this.URL = url;
this.Caption = caption;
}
public string URL {
get { return ReadAttribute("href"); }
set { AddAttribute("href", value); }
}
public string Caption {
get { return this._caption; }
set { this._caption = value; }
}
public override string HtmlBody() {
return Caption;
}
}</code></pre>
Constructors
UIObject(string)
Initializes a new instance of UIObject.
public UIObject(string htmlType)
Parameters
htmlType
stringHTML Tag (e.g. table, div, input, img etc.).
Properties
CloseElement
Specifies whether the element has a close tag. Some HTML element don't have a close tag, e.g. IMG and INPUT.
public bool CloseElement { get; set; }
Property Value
Remarks
The default value to this property is true.
HtmlElement
Get the base HTML Tag set on constructor.
public string HtmlElement { get; }
Property Value
HTMLId
Gets or sets the HTML Element ID.
public string HTMLId { get; set; }
Property Value
StyleName
Gets or sets the Style attribute to the HTML Element.
public string StyleName { get; set; }
Property Value
Methods
AddAttribute(string, string)
Adds one attribute to the Element.
public void AddAttribute(string name, string value)
Parameters
Remarks
The HTML supports some attributes without value, such as READONLY on the INPUT tag. In this case you can add NULL as the attribute value.
HtmlBody()
Determines the value which will be added into the HTML Tags.
protected abstract string HtmlBody()
Returns
- string
Value to be added into the HTML TAG.
ReadAllAttributes()
Returns all Attributes added to the element.
protected string ReadAllAttributes()
Returns
- string
Element Attributes in HTML Format.
ReadAttribute(string)
Returns the value of one attribute.
public string ReadAttribute(string name)
Parameters
name
stringAttribute Name.
Returns
- string
Element Value: if the element exists. Element Name: if the element exists and the value is null. Null: if the element isn't exists.
RemoveAttribute(string)
Removes one attribute element.
public void RemoveAttribute(string name)
Parameters
name
stringAttribute Name.
ToHtml()
Return the UIObject as a HTML string.
public virtual string ToHtml()
Returns
- string
HTML string