ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
ASP Dot Net Tutorial - Index
ASP Dot Net Tutorial - Microsofts ASP.NET
ASP Dot Net Tutorial - Begining Web Forms
ASP Dot Net Tutorial - User Controls
ASP Dot Net Tutorial - ADO .NET
ASP Dot Net Tutorial - DataBinding to WebControls
ASP Dot Net Tutorial - DataList Controls
ASP Dot Net Tutorial - DataGrid Control
ASP Dot Net Tutorial - Advance Practical Examples on DataGrid
ASP Dot Net Tutorial - Working with DataSets
ASP Dot Net Tutorial - Working with XML
ASP Dot Net Tutorial - Forms Based Authentication
ASP Dot Net Tutorial - Windows Based Authentication

Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses


  Home > Courses, Tutorials & eBooks > ASP.NET Tutorial > Microsoft's ASP.Net

ASP.NET Tutorial - Microsoft's ASP.NET

                                                                                                               Page 6 of 6


Directives control the compilation of an ASP.NET page. The beginning of a directive is marked with the characters <%@ and the end with %> character. This is shown in line 1 of the example above. A directive can appear anywhere in the page but by convention, a directive appears typically at the top of an ASP.NET page. There are two types of directives:

Page Directives

This directive appears on the top of an ASP.NET page. It specifies which programming language is being used to write an ASP.NET page. For example if we want to use VB as our page language, we will use the following directive:

<%@ Page Language=”VB”%>

And if it is C# then we use the following directive:

<%@ Page Language=”C#”%>

Import Directives

By default, only certain namespaces are automatically imported into an ASP.NET page. Referring to a class that isn’t a member of one of the default namespaces, you must explicitly import the namespace of the class. For example look at this directive:

<%@ Import Namespace=”System.Web.Mail” %>

This line imports all of the classes of the System.Web.Mail namespace, to send the mail through the SmtpMail class. This class is contained in the System.Web.Mail namespace as shown in the Example 5.1 below:


<%@ Import Namespace="System.Web.Mail" %>

<Script Runat="Server">

Sub Page_Load

Dim mailMessage As SmtpMail

mailMessage.Send( _

"", _

"", _

"Sending Mail!” _


End Sub





<h2>Email Sent!</h2>




The output of this example is shown below:

In this example, the first line contains an import directive. Without the import directive, the page would generate an error because it would not be able to resolve the SmtpMail class.

Code Declaration Block

You can see that line 3 to 7 (of Example 5 Message.aspx) contains a block of code called a code declaration block. This looks like the client server code. This is the code that ASP.NET uses to process its pages, and it is here that you will handle all the web pages functionally. This code is also compiled into MSIL.

Code Render Block

Starting from line 9(of Example 5 Message.aspx), the HTML page begins. This contains the code contents that will be sent to the browser (along with whatever your ASP.NET code spits out).

Line 13 (of Example 5 Message.aspx) begins with <%. This is known as the code render block. It contains additional instructions that ASP.NET pages uses to produce output. In the above case, it tells the ASP.Net page to write, “This is ASP.NET Page” to the browser.

Code render blocks are not as efficient as code declaration blocks. These blocks are not compiled.

ASP.NET Controls

ASP.NET controls can be freely interspersed with the text of HTML content of a page. The only requirement is that, the controls should appear within a <form Runat=”Server”> tag as shown in line 16 (of Example 5 Message.aspx). For certain tags such as <span Runat=”Server”> and <ASP:Label Runat=”Server”/>, this requirement can be ignored without any dire consequences.

One significant limitation of ASP.NET page is that it contains only one <form Runat=”Server”> tag. This means that you can not group ASP.NET into multiple forms on a page. And if you try this you will get an error.

Server Side Comments

Line 25 to 29 (of Example 5 Message.aspx) shows the server side comments code. Comments can be added to ASP.NET page by using server-side comment blocks. The beginning of the server side comment is marked with the character <%-- and the end with characters --%>. Server side comments can be added to a page for the purpose of documentation.

Note that you can not see the contents of server-side comment tags, unlike normal HTML comment tags, by using the View Source command on your browser.

Server side comments are also useful when you are debugging an ASP.NET page. You can temporarily remove both ASP.NET controls and code render blocks from a page by surrounding these elements with server side comments.

Server Side Include Directives

You can include a file in an ASP.NET page by using one of two forms of the server side include directive. If you want to include a file that is located in the same directory or in a subdirectory you can use the following directive:

<! -- #INCLUDE file=”includefile.aspx” -->

Alternatively, you can include a file by supplying the full virtual path. For example, if you have a subdirectory named expertDirectory under the wwwroot directory, you can include a file from that directory like this:

<! -- #INCLUDE virtual/expertDirectory/includefile.aspx” -->





Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
© ExpertRating 2015. All Rights Reserved.