1. <%>
This format is actually the same as ASP, but in ASP, It is VBScript or
JavaScript code, and the language supported by. NET is used in Asp.net. Special
Note: The Server Control cannot contain the <%> syntax. Otherwise, an error occurs. As follows, we can
The following code is displayed on the. ASPX page:
1 <%
2 int a = 2;
3 int b = 3;
4 int c = a + b;
5 Response.Write(c);
6 %>
Ii. <% # %>
This format is unique under Asp.net. It is the control data binding syntax and must call this
The databind () method of the control is executed (or the whole page. databind () is
The resulting controls call the databind () method.
Note: Only the server control can use the <% # %> syntax Aspx. CS Code as follows:
1 <div>
2 Server Control:<asp:TextBox runat="server" Text="<%#text%>"></asp:TextBox><br /><!--Server Control-->
3 Client Control:<input type="text" value="<%#text%>" /><!--Client Control-->
4 </div>
Code
Protected string text; // note that this field must be declared as public or protected. Otherwise, the ASPX page (subclass) cannot be accessed.
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
This. Text = "aaaaaaaaaaa ";
This. textbox1.databind (); // or this. databind ();
}
}
Iii. <% = %>
This format is often used.
<label ><%=DisplayStr()%></label><br />
<label runat="server"><%=DisplayStr()%></label>
Aspx. CS code:
Public string DisplayStr () // note that a return value must be returned. Otherwise, a runtime error may occur.
{
Return "bbbb ";
}
Iv. <% $ %>
Used to reference external resources
Note: 1. Only server controls can be bound.
2. It can only be bound to a property of the server control.
To obtain the web. config resource for an instance, follow these steps:
Code
<Asp: TextBox runat = "server" ID = "cc" Text = "<% $ ConnectionStrings: pubs %>"> </asp: TextBox>
The web. config file is as follows:
<ConnectionStrings> <add name = "pubs" c providerName = "System. Data. SqlClient"/> </connectionStrings>
In this way, it can run normally.
If you modify files in aspx: Use the client control
<Input type = "text" value = "<% $ ConnectionStrings: pubs %>"/>
Or: do not bind to a property of the server control.
<Asp: TextBox runat = "server" ID = "cc"> <% $ ConnectionStrings: pubs %> </asp: TextBox>
The same error will occur during running:
"Analyzer error message: a text expression similar to" <% $ connectionstrings: pubs %> "cannot be used. use another one ......
Finally, we stressed:
<% # %> Is only applicable to Data Binding of server controls. Therefore, it cannot be used together with <% =%> and <%>.