ankitweblogic logo
W e b t u t o r i a l s

Website

Intro to ASP.NET

ASP.NET Web Forms

Standard Controls

Label Control

TextBox Control

Image Control

Button Controls

Redirecting User

Using HyperLinks

RadioButton Control

RadioButtonList

CheckBox Control

CheckBoxList Control

DropDownList

ListBox Control

ImageMap Control

Master Page

View State

Event-Driven Programming

IsPostBack

Structure of an ASP.NET Page

Visibility of Controls

Formatting Controls

Applying CSS

Dynamic CSS

Using Style Class

Themes and Skins

Panel Control

PlaceHolder Control

AdRotator Control

Calendar Control

Validation Controls

Page Navigation

User Control

Separating Code From Presentation

Overview of ADO.NET

Data Binding

Binding Data to a List Control

Structure of an Asp.net page

The main components of an ASP.NET page are:
• Directives
• Code Declaration Blocks
• ASP.NET Controls
• Code Render Blocks
• Server-Side Comments
• Server-Side Include Directives
• Literal Text and HTML Tags.

Directives

A directive controls how the page is compiled. It is marked by the tags, <%@ and %>. It can appear anywhere in a page. But, normally it is placed at the top of a page. The main types of directives are:
• Page
• Import

A Page directive is used to specify the default programming language for a page.
<%@ Page Language="C#" %>
      OR
<%@ Language="C#" %>

Some namespaces are imported into an ASP.NET page by default. If you wish to use a class that is not contained in the default namespaces, you must import its namespace.
<%@ Import Namespace="System.Data.SqlClient" %>

Code Declaration Blocks

A code declaration block contains all the application logic for a page. It also includes declarations of global variables, and functions. It must be written within the script runat= "server" tag.
The <script> tag has two optional parameters:
• Language: You can specify the programming language to be used within the <script> tag. Otherwise, the language specified in the Page directive is used.
• SRC: You can specify an external file that contains the code block.
There is no difference in output between writing the code on the same page and including an external script file.

ASP.NET Controls

ASP.NET controls can be mixed with text and static HTML in a page. All controls must appear within a <form runat= "server"> tag. Some controls such as <span runat= "server"> and the Label control can appear outside this tag. You can have only one form per page in ASP.NET.

Code Render Blocks

If you wish to execute code within HTML, you can include the code within code render blocks. There are two types of code render blocks:
• Inline Code: It executes a statement or series of statements. It is marked by the characters <% and %>.
• Inline Expressions: They display the value of a variable or method. They can be considered as shorthand notation for the Response.Write method. They are marked by the characters <%= and %>.

Output:


Server-Side Comments

You can add comments in server-side code using the characters <%-- and --%>. The main use of these comment blocks is to add documentation to a page.

Server-Side Include Directives

You can include a file in an ASP.NET page by using a server-side include directive. It is executed before any of the code in the page. If the file is in the same directory or in a sub-directory of the page including the file, this directive is written as:
<!-- #INCLUDE file="includedfile.aspx" -->

You can also specify the virtual path of the file. To include a file located in the directory MyAspx under the wwwroot directory, you will write the directive as:
<!-- #INCLUDE virtual="/MyAspx/includedfile.aspx" -->

Note: It is recommended that you avoid using server-side include directives. It is better to use user controls.

HTML Tags and Literal Text

You can build the static part of an ASP.NET page using HTML tags and literal text. The HTML content of your page is also compiled along with the rest of the contents.
The literal text has been made bold and converted to uppercase before being rendered in the browser.

Output