SIMILARITY AND DIFFERENCE BETWEEN LABEL AND LITERAL CONTROL

Today in Engineer's World, we are discussing a topic of C# in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR  +ASP.NET SOLUTIONS

Click imagination hunt to see latest Blogs


SIMILARITY AND DIFFERENCE BETWEEN LABEL AND LITERAL CONTROL

Similarity(S) between Label and Literal Control

S1. Label and Literal both control used to show text.
S2. Both are server control.
S3. Both controls having Text property.

Difference(D) between Label and Literal Control

D1. Label control is surrounded by span tag whereas Literal control is directly written as it is. You can check on the “view page source” of the browser.
For ex-
On the designer page, you write the code as

Practical Implementation: -

<asp:Label ID="Label1" runat="server" Text="Label Control"></asp:Label>
<br />
<br />
<asp:Literal ID="Literal1" runat="server" Text="Literal Control"></asp:Literal>

But, in page source of browser, you got the code as

<span id="Label1">Label Control</span>
<br />
<br />
Literal Control

D2. Literal control is much lighter than Label control. As seen above.

D3. We can apply styling to Label control. Like changing its font to bold and color to red and backcolor to yellow. But there is no such styling property in Literal property. For Literal, we have to do the styling in code behind file like.
For ex-

Practical Implementation: -

//Applying style on Label Control
Label1.Text = "Label Control";
Label1.ForeColor = System.Drawing.Color.Yellow;
Label1.BackColor = System.Drawing.Color.Orange;
Label1.Font.Bold = true;

//Applying style on Literal Control
Literal1.Text = "<b><font color=\"Red\">Literal control</font></b>";

D4. We follow the basic HTML in a Literal control.
NOTE: To use double inverted comma, we use this \".

For any query, comment us below.


Related Questions: -


Q-1 Match the following?

a) Literal Control ----------------- i. SingleLine, MultiLine, Password
b) Label Control ------------------ ii. CommandName
c) TextBox Control -------------- iii. Convert to span tag in HTML
d) Button Control ---------------- iv. PassThrough, Encode, Transform mode

(A) a-iv, b-iii, c-ii, d-i
(B) a-ii, b-iv, c-i, d-iii
(C) a-ii, b-i, c-iii, d-iv
(D) a-iv, b-iii, c-i, d-ii
Ans- Option(D) a-iv, b-iii, c-i, d-ii

Click imagination hunt to see latest Blogs

Keep learning and sharing...

Comments

Popular posts from this blog

SSC CGL 2016 Tier-1 Marks / Result

DATA TYPES IN C#

Pattern printing program

IS STRING MUTABLE OR IMMUTABLE IN .NET?

Top Mutual Funds