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 C#, you can write this line as: <%@ Page Language="C#" %> Here is an example: <%@ Page Language="C#" %> <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.
There are various types of places where you will write your code. As seen above, you can create delimiting sections where you can write your code. Some other types of code will require that you create your code in the head section. To write ASP.NET code in the head section, you must create a script.To start creating a script in the head section, starts a <script> tag and close with an end </script> tag. Here is an example: <%@ Page Language="C#" %> <html> <head> <script> </script> <title>Exercise</title> </head> <body> </body> </html> The <script> tag uses various attributes. To start, you must specify that the script will run on the server. To do this, add an attribute named runat to the tag and assign the server string to it. This can be done as follows: <%@ Page Language="C#" %> <html> <head> <script runat="server"> </script> <title>Exercise</title> </head> <body> </body> </html> After doing this, you can create your code between the starting <script> and the end </script> tags. When writing your code, because you have determined that the page will use the C# language, you can simply write your code as you see fit. Still, you have the option of choosing among various languages. The available languages are C#, VB, VBSscript, JavaScript, JScript, or ECMAScript. To let you specify the language, the <script> tag is equipped with an attribute named language. To specify the language, assign it to the language attribute. Here is an example: <%@ Page Language="C#" %> <html> <head> <script language="C#" runat="server"> </script> <title>Exercise</title> </head> <body> </body> </html> If you don't specify the language, C# is assumed. Besides the language, you can specify how the code of your script will be formatted or considered. To support this, the <script> tag is equipped with the type attribute. To specify it, assign:
Here is an example: <%@ Page Language="C#" %> <html> <head> <script language="C#" type="text/C#" runat="server"> </script> <title>Exercise</title> </head> <body> </body> </html> Remember that only the runat attribute is required. The others are optional. After specifying the values of the desired attributes, you can create your code.
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#, the line that contains a comment can start with //. Here is an example: // This line will not be considered as part of the code You can also start a comment with /* but you must end it with */. Such a comment can cover one or more line. That is, anything between /* and */ is considered a commented section.
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 . To restore the list, you can click the Categorized 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. |
|
|||||||||||||||||||||||||
|