"ASP 10" first ASP. NET application-processing form (1)

Source: Internet
Author: User
Tags html form

We created an HTML form that shows the guests invited to the party, but when the guest clicks the Submit RSVP button, the same page is displayed repeatedly. To work around this problem, you need to implement a piece of code that performs related processing when you publish form data to the server.

The top of the Default.aspx file contains the following elements:

This is called the page directive, and the attributes defined by the page directive provide ASP. NET. NET provides details about the Web Forms file. The codebehind property value for this page directive tells the ASP. NET platform, which C # class file in this project is associated with this Web form. In this example, it is the Default.aspx.cs file, the code-behind file for Default.aspx. In other words, the program code that needs to be run in the Default.aspx page is placed in Default.aspx.cs.

In Solution Explorer for Visual Studio, the default is to hide the Default.aspx.cs file from the Default.aspx node, and you need to click the arrow to the left of the Default.aspx node to see the visual Studio hides the file (shown in 1-9), where one file is the Default.aspx.cs file referenced by the Codebehind attribute.

Figure 1-9 Expanding default.aspx in the solution Year resource Manager

Double-click the Default.aspx.cs file to open the file in the editor, which displays the code shown in Listing 1-9.

Code Listing 1-9 The initial contents of the Default.aspx.cs code-behind file

The code-behind class is based on System.Web.UI.Page, which contains many methods and properties for responding to WEB requests. The second section describes the page class in detail. This chapter uses only the Page_Load method in the code-behind class, and when there is a request for the Default.aspx file, the ASP. NET Framework calls the method in response to the above request.

For this example, the Page_Load method is called when the page is first loaded and is called again when the user submits the form. (The second part explains why this is happening.) Code that is added to the Page_Load method in response to the request is shown in Listing 1-10.

Code Listing 1-10 Adding code to the Page_Load method

Please refer to the next section for code interpretation.

"ASP 10" first ASP. NET application-processing form (1)

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: 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.