Display Controls in ASP.NET

Introduction and Demonstration

Display controls simply render text or images to the browser. Here is list of such controls.

ControlPurpose
ImageDisplays the image specified in the control's ImageUrl property.
LabelDisplays the text specified in the control's Text property.
PanelGroups a set of controls (like a Frame control in Windows).
TableDisplays a table of information. This control has two collections: TableRows, which contains the rows, and TableCells, which contains the columns in a row.
TableCellRepresents a cell in a row of a Table control.
TableRowRepresents a row inside a Table control.

The syntax of these web controls is as follows:

<asp:Label ID="MyLabel" Text="This is a Label Control" BorderStyle="solid" BorderColor="Green"
    runat="Server" />
<asp:Image ID="MyImage" ImageUrl="aspnet.gif" runat="Server" />
<asp:Panel ID="MyPanel" BackColor="lightblue" BorderColor="Green" BorderWidth="1">
    <asp:Label ID="MyLabel2" Text="Static Text within the Panel" runat="Server" />
    <br>
    <asp:TextBox ID="PanelTB" Text="TextBox inside Panel" runat="Server" />
</asp:Panel>

They can then be accessed programmatically with a code fragment like the following:

MyLabel.Text = "New Label"
MyImage.ImageUrl = "NewImage.gif"
MyPanel.BackImageUrl = "NewImage.gif"

Index.aspx Page

<%@ Page Language="vb" %> 
<html>
<
head>
    <title>Display Control Example</title>
    <script runat="server">
Sub Page_Load( )
MyLabel.Text = "New Label"
MyImage.ImageUrl = "aspnetian.jpg"
End Sub
    </script
>
</head>
<
body>
    <h1>
        Display Control Example</h1>
    <form id="Form1" runat="server">
    <asp:Table ID="MyTable" border="1" CellPadding="5" CellSpacing="0" runat="server">
        <asp:TableRow ID="Tablerow1" runat="server">
            <asp:TableCell ID="Tablecell1" colspan="2" runat="server">
Table Control
            </asp:TableCell
>
        </asp:TableRow>
        <asp:TableRow ID="Tablerow2" runat="server">
            <asp:TableCell ID="Tablecell2" runat="server">
Label Control:
            </asp:TableCell
>
            <asp:TableCell ID="Tablecell3" runat="server">
                <asp:Label ID="MyLabel" Text="This is a Label Control" BorderStyle="solid" BorderColor="Green"
                    runat="Server" />
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow ID="Tablerow3" runat="server">
            <asp:TableCell ID="Tablecell4" runat="server">
Image Control:
            </asp:TableCell
>
            <asp:TableCell ID="Tablecell5" runat="server">
                <asp:Image ID="MyImage" ImageUrl="image.jpg" runat="Server" />
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow ID="Tablerow4" runat="server">
            <asp:TableCell ID="Tablecell6" runat="server">
Panel Control:
            </asp:TableCell
>
            <asp:TableCell ID="Tablecell7" runat="server">
                <asp:Panel ID="MyPanel" BackColor="lightblue" BorderColor="Green" BorderWidth="1"
                    runat="server">
                    <asp:Label ID="MyLabel2" Text="Static Text within the Panel" runat="Server" />
                    <br>
                    <asp:TextBox ID="PanelTB" Text="TextBox inside Panel" runat="Server" />
                </asp:Panel>
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    </form>
</body>
</
html>

HAVE A HAPPY CODING!


Similar Articles