Home

Introduction to Web Coding

 

Introduction

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 C#.

Code Delimiters

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. Everything between <% and %> is part of the script and is reserved only for the script.

Your Language of Choice

By default, ASP.NET is primarily supported with Microsoft Visual Basic, Visual C#, and Visual J#. 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, C#, or J#. For example, if you will be using Visual Basic, 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 in the above code 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 C#.

Code Comments

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 C#, to start a comment, you can type // followed by some texrt. Here is an example:

// This line will not be considered as part of the code

Everything on the right side of // is considered a comment. You can create many lines of comments by simply starting each with //. Here is an example:

// This web-based application is used to process
// customers transactions and to create new provisions
// The clerk performing the transactions must pay close attention
// to details, including those details that seem insignificant.

C# supports another type of comment. Its starts with /* and ends with */. Everything between /* and */ is considered a comment. Here is an example:

/* This form will be used for customer to make a reservation */

Remember that the comment must start with /* and end with */. As opposed to the // type that covers only one line of comment, the /* and */ combination is a good candidate to create a commented section that would cover more than one line. Here is an example:

/* This web-based application is used to process
   customers transactions and to create new provisions
   The clerk performing the transactions must pay close attention
   to details, including those details that seem insignificant. */

Comments are very useful and you are strongly suggested to use them regularly. They can never hurt your code. 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.

Application Management Windows

 

The Solution Explorer

Solution Explorer The Solution Explorer is a window that displays the "physical" items used in your project.

The items of this window display in a tree. To expand a node, you can click its + button. To collapse it, click its - button. To explore an item, you can double-click it. The result depends on the item you double-clicked.

 

The Properties Window

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 2005 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 2005. 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 . To restore the list, you can click the Categorized button Categorized.

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.

Properties Categories

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.

 

Previous Copyright © 2005-2007 FunctionX, Inc. Next