An ASP.NET application is a series of files that
contain code. To write this code, you can use one or more languages. The
primary language used in most web pages is HTML. To enhance the behaviors
of your web pages, you can add scripted code to them. The code you write
must be an appropriate language. ASP.NET supports various languages,
including Visual Basic.
When developing your web pages, you can include HTML
and scripting code in the same file but you must distinguish them. While
HTML uses its own tags, to show the beginning of an Active Server Pages
script, you must type <%, which is called a delimiter. To show the
end of that section, you must type %>, which is also called a delimiter.
Here is an example:
<html>
<head>
<title>Exercise</title>
</head>
<body>
<% %>
</body>
</html>
most of the time, you will write each delimiter on its
own line. Here is an example;
<html> <head> <title>Exercise</title> </head> <body> <% %> </body> </html>
This technique is not a rule. Sometimes it simply makes your
code easier to ready. Everything between <% and %> is part of the script and is reserved
only for the script.
Although we created only one delimiting section, you can
create as many delimiting sections as you want. Here are examples:
<html>
<head>
<title>Exercise</title>
</head>
<body>
<% %>
<% %>
<% %>
</body>
</html>
Of course, you can create the sections where each delimiter
is on its own line:
<html> <head> <title>Exercise</title> </head> <body> <% %> <% %> <% %> <% %> </body> </html>
Between an opening delimiter <% and a closing
delimiter %>, you can add the necessary ASP code, which can consist of
ASP code, HTML code, and others. Before an opening delimiter <% or after a
closing delimiter %>, you can add HTML code as you want but no ASP code:
<html> <head> <title>Exercise</title> </head> <body> HTML Code <% ASP Code, HTML Code, Scripting Code %> HTML Code <% ASP Code, HTML Code, Scripting Code %> HTML Code <% ASP Code, HTML Code, Scripting Code %> HTML Code </body> </html>
By default, ASP.NET is primarily supported with
Microsoft Visual Basic, Visual C#, VBScript, and JavaScript. Many other languages are
supported also. To specify the language of your choice, in the first
line of your page, you can use the following formula:
<%@ Page Language="FavoriteLanguage" %>
The FavoriteLanguage factor must be the name of
the language you use for your code. It can be VB or C#. For
example, if you will be using VB, you can write this line
as:
<%@ Page Language="VB" %>
Here is an example:
<%@ Page Language="VB" %>
<html>
<head>
<title>ASP.NET Tutorials</title>
</head>
<body>
<h1>Lesson 2: Active Pages</h1>
<p>This lesson shows different ways of displaying items on a
web page. The instructions involve both HTML and scripts</p>
<h3>Enjoy</h3>
</body>
</html>
In the same way, you can replace VB with C#
or JScript.
As you may be aware, each language has its own rules
that you must follow when programming in it. Just
changing the name of the language from the above line and leaving the rest
of the code unchanged doesn't complete the job; in fact, simply changing
the name of the language is a guaranty that some of the code on the page
would not work anymore.
In our lessons, we will mostly use VB.
In the programming world, a comment is text that
the compiler would not consider when reading the code. As such a
comment can be written any way you want. In Visual Basic, the line that contains a comment
can start with a single quote. Here is an example:
' This line will not be considered as part of the code
Alternatively, you can start a comment with the Rem
keyword. Anything on the right side of rem, Rem, or REM would not be
read. Here is an example:
Rem I can write anything I want on this line
Comments are very useful and you are strongly
suggested to use them regularly. They can never hurt your code
and they don't increase the size of your application. Comments can
help you and other people who read your code to figure out what a
particular section of code is used for, which can be helpful when
you re-visit your code after months or years of not seeing it.
You will regularly need to expand your code on more
than one line. This happens if you are writing an expression
that involves many entities that must belong to a group.
To continue a line of code to the next,
type an empty space followed by an underscore symbol, then continue your
code on the next line.
A property is a piece of information that characterizes or
describes a control. It could be related to its location or size. It
could be its color, its identification, or any visual aspect that gives
it
meaning.
The properties of an object can be changed either at design time
or at run time. You can also manipulate these characteristics both at
design and at run times. This means that you can set some properties at
design time and some others at run time.
To assist you with setting the properties of a web control, Microsoft
Visual Studio 2008 provides the Properties window. By default, it displays
in the lower right section of the interface. If it is not available, on
the main menu, you can click View -> Properties Window.
To manipulate the properties of a control at design time, first
add the desired
object from the
Toolbox to the web form. To change the properties of a control at
design time, on the form, click the control to select it. Then use the
Properties window:
The items in the Properties window display in a list
set when installing Microsoft Visual Studio 2008. In the beginning, you may
not be familiar with the properties because the list is not
arranged in a strict order. You can rearrange the list. For
example, you can cause the items to display in alphabetical order. To do
this, in the title bar of the Properties window, you can click the Alphabetic
button
When a control is selected, the Properties window
displays only its characteristics. When various controls have been selected, the
Properties window displays only the characteristics that are common to the
selected controls.
Each field in the Properties window has two sections: the property’s
name and the property's value. The name of a property is represented in the left column. This is the
official name of the property. The names of properties are in
one word. You can use this same name to access the property in code.
The box on the right side of each property name represents the value of
the property that you can set for an object. There are various kinds of
fields you will use to set the properties. To know what particular kind a
field is, you can click its name. To set or change a property, you use
the box on the right side of the property’s name: the property's value,
also referred to as the field's value.
|
ASP.NET: Types of Applications
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment