In the Web page special effects code
The position of the HTML display content (that is, the content between the start and end tags, such as <div> here </div> (HTML tags) or <asp tutorial: Label id= "Label2" runat= "Server" text = "Label" > Here </asp:label> (server-side control), which displays the variable as a placeholder in the symbol
For the first position, there are some constraints:
(1) The general attribute requirements are string or numeric (some server-side attributes support attributes as data sets);
(2) Not all properties can be bound to variables, some properties such as the Runat property must be a "server" constant, even if the bound string is a server, will cause parser parsing error;
(3) There is a property, he requires the attribute value has constraints (type constraints, such as server-side control requirements TabIndex attribute is short type, or string content has constraints), should also be satisfied at the time of binding, otherwise it may still compile the times wrong;
(4) Also a property, although the property itself has constraints, but even if the bound variable does not meet the constraints, you can compile through, such as the checked property of input, it only checked string is legitimate, but if the string obtained through the binding is not checked, Then these attributes will have their own internal processing mechanism, to ensure the normal use;
(5) Also note that even for the same class of properties, server-side and HTML properties of the processing mechanism is also different, the same is TabIndex (TabIndex), the former if not satisfied, the parser error, the latter ignores this problem.
For the second location, it is generally as long as the background variables that are bound are compatible with the data types in JavaScript.
For the third location, if the binding appears in a location that is not inside the server-side control, there is no constraint, as long as the constant string can appear in a position that can be bound. However, there are constraints to the way that is placed inside the server-side control, which is the <asp:label id= "Label2" runat= "Server" text= "label" > here </asp:label>. By summarizing, it concludes four Class server-side control, if the bound code appears between the opening and closing tags of these controls (where the control refers to a layer of nested controls outside the binding code, which is the most inner control surrounding the bound code), there are different display results:
(1) Constrained controls: This type of control requires that its start and end labels contain only the specified child controls, so if a code block appears here, the error is compiled. For example:
<asp:datalist runat= "Server" ></asp:datalist>, between which requires that <itemtemplate></itemtemplate> be nested.
(2) non-nested class controls: Such controls, which do not allow internal nesting of other controls or labels, can only be constant strings, which take the contents of the constant string in the start and end tags as his properties. For example, the textbox mentioned above will use the contents of the label as its Text property value.
(3) Nested class controls: Such controls can nest any other control or contain strings, so the string content represented by a bound code block can be displayed normally. such as label controls, panel, and so on.
(4) Data-bound class controls: This type of control is a server-side control provided by the ASP.net tutorial, and can be bound to a data collection (only the second way it can be done), in addition to the normal variable type.
about whether to enclose quotes: should <%= str%> or <%# str%> be placed in single or double quotes when used in the above three locations? For different locations, the way of handling is different: (specifically please in the following two ways of specific introduction, to be experienced)
(1) for the first position, because JavaScript is weakly typed, it is always true if the binding is quoted as a string, and it is all right, and if the binding is not quoted, it will think it is a numeric type, so if you get a real number, you can, of course, if it's a non-numeric type, will produce a script error, which is the same even for JavaScript assignment constants:
The following are the referenced contents:
var test1 = 123b;//run times wrong
var test2=123;//is correct and is a numeric type
var test3= "123b";//correct, String type
The front desk that is spoken here is usually. aspx file, which refers to the codebehind associated with ASPX, and the file suffix named. aspx.cs; On the other hand, the binding here refers to the user to send access to a page instruction, the server side in the execution of the foreground code has been assigned, and then generate HTML format return Client display, not already displayed to the client, and then through other methods (such as AJAX) to the server to get the corresponding variables