C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Code that uses LiteralControl: C#
static public string TimeString()
{
return DateTime.Now.ToString("h:mm:ss");
}
protected void Page_Load(object sender, EventArgs e)
{
LiteralControl literal = new LiteralControl("<!-- " +
TimeString() + " -->");
Page.Controls.Add(literal);
}
Tip: This method is static. It uses no instance members on the class. More information on static methods is available.
Static MethodNote: Look at how we use the constructor. We specify that we want an HTML comment. The TimeString() method is called.
And: This returns the "2:26:42" style time string. We put it in the HTML comment.
Finally: In the above code, we append the LiteralControl to the document. This is an object-oriented way to add the comment.