|
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:
- text/C# to the type attribute if you had, or will, specify
the language as C#
- text/VB to the type attribute if you had, or will, specify
the language as VB
- text/vbsscript to the type attribute if you had, or will,
specify the language as VBScript
- text/javascript to the type attribute if you
had, or will, specify the language as JavaScript
- text/jscript to the type attribute if you had, or will,
specify the language as JScript
- text/ecmascript to the type attribute if you had, or will,
specify the language as ECMAScript
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.