What Literal control is used for in asp.net? and What is the difference between them and Label control?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The major difference is that the Label Control adds the span tag to the text (property) you set, allowing to apply a style to it:
The Literal Control allows you to render any kind of content. You can use it to render scripts, hmtl and any other type of document content. It doesn’t change the string you provide in the Text property.
Note: the Label control allows you to render straight HTML too, but it puts all your text in span tags as mentioned. So, for rendering large HTML portions a Literal control is the way to go.
P.S.: In HTML there is a
<label>tag. If you use theAssociatedControlIdproperty of the Label control, it will render as HTML<label>(thanks to Ray for pointing that out.)For example:
Will render as:
See also here on W3 Schools.