foreground bind background variable method summary (1/4)

Source: Internet
Author: User
Tags bind constant

Asp tutorial. net foreground bind background variable method summary

You may often encounter the problem of using (or binding) the variable value in the background code in the front-end code. Generally, there are two methods: <% = str %> and <% # str %>. Here is a brief summary. If you have any errors or objections, please kindly advise.
On the one hand, the front-end is common. aspx file. The background refers to the codebehind associated with aspx. The file suffix is. aspx. cs; on the other hand, binding here means that after a user sends a command to access a page, the server has assigned a value to the front-end code during execution, after the html format is generated, it is returned to the client for display, instead of being displayed to the client. Then, you can use other methods (such as ajax) to obtain the corresponding variables on the server.

Note: the two files mentioned above are in the code-behind mode and the code-beside (inline) mode, that is, only one aspx file exists, the background code is written into the <script type = "text/webpage effect" runat = "server"> </script> of this file (there are some syntax differences ), this has a slight impact on the issues discussed in this article, because code embedding is a compilation of declarative code and c #/ code into a class, while code hiding separates declarative code from c #/ code several times for translation/Compilation. Therefore, the former is partial and partial (partial) the relationship between the latter base class and the derived class, but this only affects the range of variables that can be bound (related to modifiers. The following uses the code hiding mode as an example.

Generally, backend variables may be used (bound) in three front-end code locations:

Server-side control attributes or html tag attributes
Javascript code
The location of the html display content (that is, the content between the start tag and the end tag, for example, <div> here </div> (html tag) or <asp: label id = "label2" runat = "server" text = "label"> here </asp: label> (server-side control ), it is used as a placeholder to display variables at the position where the symbols appear)
For the first position, there are some constraints:

(1) the general attribute requirements are string or numeric. (some server attributes support data sets );

(2) not all attributes can be bound to Variables. For example, the runat attribute must be a constant of "server". Even if the bound string is a server, an error occurs during analyzer analysis;

(3) There is an attribute that requires the attribute value to be constrained (type constraints, for example, the server-side control requires that the tabindex attribute be of the short type, or the string content is constrained ), it should also be met during binding; otherwise, an error may still be reported during compilation;

(4) another property. Although the property itself has constraints, it can be compiled even if the bound variable does not meet the constraints, such as the checked attribute of input, only the checked string is valid, but if the string obtained by binding is not checked, these attributes will have their own internal processing mechanism to ensure normal use;

(5) pay attention to the fact that, even for the same class of attributes, the processing mechanisms of the server side and the html attributes are also different. The same is tabindex (tabindex). If the former does not meet the requirements, the analyzer is incorrect, the latter ignores this issue.

For the second position, it is generally only required that the bound background variable is compatible with the data type in javascript.

For the third position, if the binding position does not exist in the server-side control, there is no constraint. As long as it is a constant string that can appear, it can be bound. However, for the control placed inside the server, that is, the <asp: label id = "label2" runat = "server" text = "label"> here </asp: label>, there are constraints. The summary is summarized into four types of server-side controls. If the bound code appears between the start and end labels of these controls (the control mentioned here, if the bound code is surrounded by multiple layers of nested controls, it refers to the inner control of the bound code), with different display results:


Homepage 1 2 3 4 Last page
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.