Page Structure in ASP.NET

Introduction – The structure of an ASP.NET page

You may now look at the official structure of an ASP.NET page. The significant components of an ASP.NET page are listed below:

  • Directives
  • Code declaration blocks
  • ASP.NET controls
  • Code render blocks
  • Server-side comments
  • Server-side include directives
  • Literal text and HTML tags

Detail description of  page structure in ASP.NET

      • Directives

        An ASP.NET page’s compilation is managed by a directive. The letters %@ and %> are used to indicate the start and end of a directive, respectively. Anywhere on a page can include a directive. However, a directive usually appears at the top of an ASP.NET page by convention.

        Page Directives

        A page directive can be used to indicate the page’s default programming language. In addition, tracing and debugging of a page can be enabled via page directives.

        <%@ Page Language="C#" %>
        <%@ Language="C#" %> 
        <%@ Page Trace="True" %>
        <%@ Page Debug="True" %>
        Import Directives

        Only a select few namespaces are by default automatically imported into an ASP.NET page. You must either use the fully qualified name of the class or explicitly import the namespace of the class if you wish to refer to a class that isn’t a member of one of the default namespaces.

        <%@ Import Namespace="System.Web.Mail" %>
      • Code Declaration Blocks

        code declaration block contains all the application logic for your ASP.NET page and all the global variable declarations, subroutines, and functions.

        <%
        Sub mySu
          ... code
        End Sub
        %>
        
        <Script runat="Server">
        Sub Sub
         ... code
        End Sub
        </Script>
        
        <Script Language="C#" Runat="Server">
        
      • ASP.NET Controls

        A page’s text and the HTML content can be freely inserted between ASP.NET controls. Only that the controls be contained in a form Runat=”Server”> tag is necessary. Additionally, this condition may be disregarded without having a negative impact on some tags

        <span Runat="Server"> and ASP:Label Runat="Server" />.
      • Code Render Blocks

        Within code render blocks, you may run code that has to be executed in your ASP.NET page’s HTML or text content. Inline code and inline expressions are the two different kinds of code render blocks. A statement or group of statements is carried out using inline code. The letters % and %> are used to start and terminate this type of code.

        <Script Runat="Server">
         Dim strSomeText As String
        
         Sub Page_Load
          welcomeText = "Welcome! the codehubs"
         End Sub
        </Script>
        
        <html>
        <head><title>Code Hubs</title></head>
        <body>
        
        <form Runat="Server">
        
        The value of welcomeText is: 
        <%=welcomeText%>
        
        <p>
        
        <% thanksText = "Thnks!" %>
        The value of thanksText is: 
        <%=thanksText %>
        
        </form>
        
        </body>
        </html>
      • Server-side Comments

        Server-side comment blocks may be used to add comments to your ASP.NET websites. The letters %— and –%> are used to indicate the beginning and conclusion of server-side comments, respectively.

        <Script Runat="Server">
         Dim strText As String
         Sub Page_Load
          strText = "Welcome!"
         End Sub
        </Script>
        
        <html>
        <head><title>Serverside comment</title></head>
        <body>
        
        <form Runat="Server">
        
        <%--
        This is inside the comments
        <asp:Label Text="Welcome to codehubs!" Runat="Server" />
        <%= strText %>
        --%>
        
        This is outside the comments
        
        </form>
        
        </body>
        </html>
      • Server-side Include Directives

        The server-side include directive comes in two different versions, either of which may be used to include a file in an ASP.NET page. The following directive would be used to include a file that is located in the same directory as or in a subfolder of the page that is including the file.

        <!-- #INCLUDE file="includefilename.aspx" -->
        <!-- #INCLUDE virtual="/myDirectory/includelogincodehubs.aspx" -->
        <!-- #INCLUDE file="<%=var%>" -->
      • Literal Text and HTML Tags

        HTML content is the last kind of element that may be used in an ASP.NET page. The static content of your website is created using standard HTML text and elements.

        <Script Runat="Server">
        
         Sub Page_Load
          Dim control As LiteralControl
        
          For each control in Page.Controls
           control.Text = strReverse( control.Text )
          Next
         End Sub
        
        </Script>
        
        <html>
        <head><title>Literal</title></head>
        <body>
        
        <b>Text is reversed</b>
        
        </body>
        </html>

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories