"Getting Started 12" the first ASP. NET application-Create a summary view

Source: Internet
Author: User

The basic structural unit of the application has been completed and the invitees have been able to respond. This section adds a support component that displays a summary of replies received so that the user's friends know who will attend the party and make the appropriate arrangements. Right-click the partyinvites item in the Solution Explorer and select Add→web form from the pop-up menu. Set the name to summary, and then click the OK button to create a new file summary.aspx, as shown in listing 1-14 of the new file.

Code Listing 1-14 contents of the Summary.aspx file

This is your first ASP. NET application, and we want to demonstrate as many tricks as possible in this chapter. For this reason, the summary.aspx file looks very different from the Default.aspx file.

Each part of the file is carefully analyzed later, but first notice that there is no form element in the summary.aspx file. The name of the Web form is somewhat misleading, although most Web applications use it, but Web forms are essentially an enhanced HTML file that is processed by ASP. For default.aspx files, this enhancement is reflected in the form of a code-behind file, so it is used to publish the form. The summary.aspx file further plays the function of the <% and%> tags to add dynamic content to the generated HTML when the browser requests this file.

The official name of the <% and%> tags is the server-side script delimiter, but it is often referred to as a snippet (code nugget). There are a variety of different types of code snippets, and two different pieces of code are added to code listing 1-14. Here is the first code snippet:

The code snippet that starts with the tag <%@ is called a directive. Directives can perform operations that affect the entire Web form. In this example, an import directive is created to include namespaces in the project into scopes for referencing classes without needing to know the class name.

Why do we care about namespaces? Because another code fragment in the list is a C # code block, the code block executes when the page is requested. Referencing a class without knowing the namespace of the class can reduce the complexity of the code. The start tag of a code block is only <%, and does not contain any other characters. (The end tag for any type of code fragment is%>.) )

Regular C # statements are used in code blocks to generate a set of HTML elements that list the invited guests in the table element. Call Responserepository.getrepository (). The Getallresponses () method gets all the data objects in the repository and uses the Where method of LINQ to select a positive reply, and then uses the Foreach loop to generate an HTML string for each data object:

Use String.Format to build the HTML string to display, which consists of the property values of each Guestresponse object, and then use the Response.Write method to add the HTML to the output sent to the browser.

"Getting Started 12" the first ASP. NET application-Create a summary view

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.