In the previous section, we briefly introduced the compounding environment of asp+, and we discussed the syntax of asp+ in this section. In fact, when you loaded NGWS, he brought the document is the best learning asp+ tutorials, you are good enough e-wen, and good patience, learning asp+ It's not difficult. We guys also learn a lot from here, this article about asp+ grammar, most also from the original m$, the most regrettable is that our server can not be installed on the NGWS, some examples, we can not see the implementation results, not very good. But in some places, I'll show you the results of the execution. Let's start this section: a asp+ page suffix name is ". ASPX. It can contain eight different syntax-marking elements. We will introduce these different syntaxes in this article and give an example to show how it is used.
<%%> and <%=%>
Have you ever used an ASP, you have used, then you will not be unfamiliar with this label. Oh, here is a simple example. The results of his implementation I think I can not write out, we all know. This is not much to talk about, hehe.
<% for (int i=0; i<8; i++)
{
%>
Hello world!
<%}%>
In the above example the program between <%%> will be executed and the results shown,<%= "Hello World"%> equals <% Response.Write ("Hello World")%>
Note: In C #, the semicolon (;) as the delimiter, but we have to pay attention to something.
C # code
<% Response.Write ("Hello World"); %>, the semicolon here is a must.
<%= "Hello world"; %> There are some small problems with this: The result is "Response.Write" ("Hello World";);
That's right
Syntax for declaring code: <%. Number = Subtract (number, 1); ...%>
Important issue: asp+ Unlike ASP, functions that can be declared in an ASP are stated in the zone, but in asp+ all functions and variables must be declared in the zone. Otherwise, an error occurs when ASPX compiles.
asp+ server-side control syntax
Controls on the server use developers to dynamically generate HTML pages and send them to customers (such as Netscape and IE, which produce different javascript.) There are also common browsers and WAP browsing received pages are also different. Their object's statement is also used in the label. But they are different from the other labels. Because they contain a "runat=server" attribute. (Oh, this attribute we also used in ASP, but the function is ...). The following example shows how a control is used.
< html>
< script language= "C #" runat=server>
void Page_Load (Object sender, EventArgs e) {
Message.Text = "Welcome to asp+";
}
</script>
< body>
< Asp:label id= "message" font-size=24 runat=server/>
</body>
In the source code above we add the ID "message":
< Asp:label id= "message" font-size=24 runat= "Server"/>
Read the above code, is not found that we write VB program, OH, first set up a good skeleton, and then to write their event processing. This is the new concept that m$ gives us.
asp+ Html server Control syntax
HTML server control, which allows developers to programmatically manipulate HTML elements. An HTML server control is just one more "runat=server" attribute than a normal HTML element. The following example illustrates the use of HTML service controls.
< script language= "C #" runat=server>
void Page_Load (Object sender, EventArgs e) {
message.innerhtml = "Welcome to asp+";
}
</script>
...
< span id= "message" style= "font-size:24" runat=server/>
The result he executed was the same as the result of the first program. Data bundle (Databinding) syntax <% #%>
Data bundling technology allows asp+ developers to closely associate the properties of a control with the value of a data container. The code in this area of <%#%> is only executed after the "DataBind" method call. The following example demonstrates its use.
Here is a value:
In this way, a control called "MyList" is programmed, and the DataBind () method is called.
void Page_Load (Object sender, EventArgs e)
{ArrayList items = new ArrayList ();
Items. ADD ("one");
Items. ADD ("two");
Items. ADD ("Three");
Mylist.datasource = items;
Mylist.databind ();
}
Object tag Syntax: < object runat= "server"/>
The OBJECT tag syntax enables developers to declare and sample an object using a basic tag. As follows:
< object id= "items" class= "System.Collections.ArrayList" runat= "Server"/>
This object is automatically created at runtime and is named items
void Page_Load (Object sender, EventArgs e) {
Items. ADD ("one");
Items. ADD ("two");
Items. ADD ("Three");
...
}
Annotation syntax:
Annotations enable developers to block execution or references to code, including controls. The following example illustrates the application of this syntax.
<%--
< Asp:calendar id= "mycal" runat=server/>
<% for (int i=0; i<45; i++) {%>
Hello World
<%}%>
--%>
SSI syntax: <--#Include file= "Locaton.inc"-->
The brother who wrote the most basic HTML is no stranger to him, so he doesn't want to talk about it any more:
<!--#Include file= "Header.inc"-->
...
<!--#Include file= "Footer.inc"-->
In the following section, we'll look at HTML controls and user controls in the future