Embed code blocks in webpages

Source: Internet
Author: User
Embed in a webpageCodeBlock

2010-02-09 20:53:54| Category:Default category| Tag: |Font SizeLargeMediumSmall Subscription

There are four types of code writing:

    • <%> Or <% = %>
    • <% @ %>
    • <% # %>
    • <% $ %>

<%> Or <% = %>

    1. MsdnArticle: Embedded code block in ASP. NET web pages
    2. Msdn location: development tools and languages ---> Visual Studio documentation ---> Visual Web Developer ---> Create an ASP. NET webpage ---> Asp. Net webpage overview ---> embedded code block in ASP. NET webpage
    3. Introduction:

      Embedded code blocks are the server code executed during page rendering. The code in the block can execute programming statements and call functions in the current page class.

      ASP. NET web pages support embedded code blocks, which are mainly used to retain backward compatibility with the old ASP technology. Generally, applying embedded code blocks to complex programming logic is not the best practice, because debugging and maintenance are difficult when code and tags on pages are mixed. In addition, because the code is only executed during page rendering, it is much less flexible than placing the code in the appropriate page processing phase to execute background code or script block code.

      Some functions of embedded code blocks include:

      • Set the value of the control element or tag element to the value returned by the function.
      • Directly embed computing into tag or control attributes.

<% @ %>

    1. Msdn article: ASP. NET web commands
    2. Msdn location: development tools and languages ---> Visual Studio documentation ---> Visual Web Developer ---> Create an ASP. NET webpage ---> Asp. Net webpage overview ---> Asp. Net webpage instruction
    3. Introduction:

      Commands specify some settings that are used by the page and user control compiler to process ASP. NET web forms pages (. aspx files) and user controls (. ascx) files.

      ASP. net processes any command block (<% @ %>) that does not contain the explicit command name as the @ page command (for pages) or the @ Control Command (for user controls.

<% # %>

  1. Msdn article: Data Binding expression syntax
  2. Msdn location: development tools and languages ---> Visual Studio documentation ---> Visual Web Developer ---> access data through ASP. NET ---> data binding expression syntax
  3. Introduction:

    The data binding expression is included in the <% # And %> delimiters and uses EVAl and bind functions. EVThe Al function is used to define one-way (read-only) binding. The BIND function is used to define bidirectional (updatable) binding. Besides calling EV in a data binding expressionIn addition to data binding, the Al and bind methods can also call any common code within the <% # And %> delimiters to execute the code During page processing and return a value.

    When the databind method of the control or page class is called, the data binding expression is parsed. Some controls, such as the gridview, detailsview, and formview controls, automatically parse the data binding expression during the prerender event of the control and do not need to explicitly call the databind method.

    Use EVAl Method

    EVThe Al method can calculate the post-bound data expression in the template of the data binding control (such as the gridview, detailsview, and formview controls. At runtime, EVThe Al method calls the ev of the databinder objectAnd reference the current data item of the container. A naming container is usually the smallest component of a data binding control that contains a complete record, such as a row in the gridview control. Therefore, you can only bind eV to the template of the data-bound control.Al method.

    EVThe Al method uses the name of a data field as a parameter and returns a string containing the value of this field from the current record of the data source. The second parameter can be provided to specify the format of the returned string. this parameter is optional. String format parameters are defined using the format method of the string class.

    Bind Method

    Bind METHOD AND EVThe Al method has some similarities, but there are also great differences. Although it can be like using EVThe Al method uses the bind method to retrieve the value of the data-bound field, but the bind method must be used when the data can be modified.

    In ASP. NET, data binding controls (such as the gridview, detailsview, and formview controls) can automatically use the update, delete, and insert operations of data source controls. For example, if you have defined SQL select, insert, delete, and update statements for the data source control, you can use the bind method in the gridview, detailsview, or formview control template, the control can extract values from the Child control in the template and pass these values to the data source control. The data source control then executes appropriate database commands. For this reason, bind functions must be used in edititemtemplate or insertitemtemplate of the data binding control.

    The bind method is usually used with the input control, for example, the Textbox Control rendered by the row of the gridview in editing mode. When the data binding control creates these input controls as a part of its own rendering, this method can extract the input value.

    The bind method uses the name of the data field as the parameter to associate with the bound property.

<% $ %>

    1. msdn article: This article is not directly described in msdn, but is used in the following article.
    2. msdn location: development tools and languages ---> Visual Studio documentation ---> Visual Web Developer ---> Asp. net Access Data ---> data binding expression syntax ---> How to: bind data to a templated control. Alternatively, the development tools and languages ---> Visual Studio documentation ---> Visual Web Developer ---> use ASP. net Access Data ---> data binding expression syntax ---> How to: bind data to the templated control of Visual Studio
    3. Introduction: ASP. NET 2.0 + obtains the tag value in the web. config file.

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: info-contact@alibabacloud.com 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.