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