Use Literal instead of Label Control to Increase Performance in ASP.NET

No.of Views1140
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  01 Jan 2011 08:01:05
Tag : ASP.NET , Application Performance Optimization
The performance is important for all website. So if a web page size is increased then loading time also increase. In this tip I will show how is label control increase page size and what is best control instead label control have to use in page in order to reduce size and increase loading speed.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

The performance is important for all website. So if a web page size is increased then loading time also increase. In this tip I will show how is label control increase page size and what is best control instead label control have to use in page in order to reduce size and increase loading speed.

Demo with Label Control

Html Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <table cellpadding="0" border="0" width="100%">
        <tr>
            <td>
                Name :<asp:Label ID="lblName" runat="server" Text=""></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Address :<asp:Label ID="lblAdd" runat="server" Text=""></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Salary :<asp:Label ID="lblSal" runat="server" Text=""></asp:Label>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

In have include three label controls on this page, let’s run and see output

Image Loading

Demo with Literal Control

Html Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page2.aspx.cs" Inherits="Page2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <table cellpadding="0" border="0" width="100%">
        <tr>
            <td>
                Name :<asp:Literal ID="lblName" runat="server" Text=""></asp:Literal>
            </td>
        </tr>
        <tr>
            <td>
                Address :<asp:Literal ID="lblAdd" runat="server" Text=""></asp:Literal>
            </td>
        </tr>
        <tr>
            <td>
                Salary :<asp:Literal ID="lblSal" runat="server" Text=""></asp:Literal>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

I have added three literal control, lets run and see output

Image Loading

Why size is increased in first than second Page?

When we use the label control in rendering with span html tags in browser, but literal control does not add any extra html tags. Let’s see generated html for both demonstration. First take look label control demo.

Image Loading

Page size: 977 bytes

Now take look generated html for literal demo.

Image Loading

Page size: 894 bytes

So as per demonstration example just with three fields we have save 81bytes.if we used 20 labels in page, the size increased 0.5KB and its increase page load time unreasonably.
Note: But if you want to access values after page render, then you must use the label control, because you cannot find the literal with id in server side.

Conclusion

In this article you have learned how to reduce page size and increase page load speed with literal control. So when you are design page, you have to choice correct control at same time keep mind your page size does not increase by unnecessary.Hopes help and thank for reading.

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top