Display Controls in ASP.NET


Introduction and Demonstration

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

Control     Purpose
********************************************************************
Image       Displays the image specified in the control's ImageUrl property.
Label        Displays the text specified in the control's Text property.
Panel       Groups a set of controls (like a Frame control in Windows).
Table        Displays a table of information. This control has two collections:
            TableRows, which contains the rows, and TableCells,
            which contains the columns in a row.
TableCell   Represents a cell in a row of a Table control.
TableRow    Represents 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 runat="server">
      <asp:table id="MyTable"
         border="1"
         cellpadding="5"
         cellspacing="0"
         runat="server">
         <asp:tablerow runat="server">
            <asp:tablecell colspan="2" runat="server">
               Table Control
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               Label Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:label id="MyLabel"
                  text="This is a Label Control"
                  borderstyle="solid"
                  bordercolor="Green"
                  runat="Server" />
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               Image Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:image id="MyImage"
                  imageurl="image.jpg"
                  runat="Server" />
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               Panel Control:
            </asp:tablecell>
            <asp:tablecell 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>

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System