"ASP 15" the first ASP. NET application-page call Codebehind code

Source: Internet
Author: User

Although you can add a C # code block to a Web Forms file, it is usually not very meaningful because the code quickly becomes difficult to read and maintain. A more reasonable and more common approach is to define a method in the code-behind file and then invoke the method using a code snippet and insert the result into the HTML that is sent to the browser. Listing 1-16 defines a new method getnoshowhtml in the Summary.aspx.cs code-behind file, which generates the same table row as in the previous section.

Code Listing 1-16 getnoshowhtml method in Summary.aspx.cs code-behind file

This method can then be called from the code snippet in the Summary.aspx file, as shown in Listing 1-17.

Code Listing 1-17 calling the code-behind method from the Summary.aspx file

This code listing uses a code snippet that starts with a <%= tag. This tells ASP. NET to insert the result of the above method into the output sent to the browser. This makes more sense and makes the code more readable than it is to include code directly on the page. The resulting HTML is similar to what was generated using the previous code snippet, and the life of rejecting the party invitation is a table row, as shown in 1-13.

"ASP 15" the first ASP. NET application-page call Codebehind code

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.