Question:
What is the difference between Literal and Label?
Answer:
Even though both controls are converted to become HTML, they have some differences.
Label control encloses the text with <span> tags, and it has some attributes that you can specify some properties like style related formattings. It also has a specific usage to be a label for a form input if the AssociatedControlId attribute is defined. For instance;
<asp:Label id="lblName" AssociatedControlId="txtName" Text="Name" runat="server" />
<asp:TextBox id="txtName" runat="server" />
is rendered as:
<label for="txtName">Name</label> <input type="textbox" name="txtName" value="" />
This associates the lblName with the txtName control. Therefore, the textbox gets focus when the label is clicked.
On the other hand, literal control simply shows the exact text that you put in without making any changes. In other words, literals are kind of light-weight labels.
- Submitted by Aaron Goldenthal