ASP. NET basic Tutorial Study Notes: 2. Web Forms

Source: Internet
Author: User

A Web application generates HTML and presents it to a browser for processing. Each request uses an HTML response for service. Generally, data is queried on a server machine, then, the server creates HTML to return the retrieved data to the browser. I. Currently, server controls are basically not used in development. But let's summarize it. The Web form model is built on a basic set of controls. These controls are server controls of ASP. NET. First, let's take a look at how they work: copy the Code <form id = "form1" runat = "server"> <div> Enter name: <input type = "text" id = "name" runat = "server"/> <br/> Gender: <select id = "gender" runat = "server"> <option> boy </option> <option> girl </option> </select> <input type = "submit" value = "Submit"/> <% if (IsPostBack) {%> <% = name. value %> is a <% = gender. value %> <% }%> </div> </form> copies the form on the Code webpage. The input and select labels are marked with the runat = "server" attribute. In asp.net, ru Nat = server can be used for any HTML element. If an element is marked with this attribute, ASP.. NET creates a server control and adds it as a field to the class derived from Page. The type of the control depends on the flag element. When the server control is used, the client interacts with the server as follows: 1. The client browser sends a Get request, ASP.. NET creates a derived class of the Page class to serve the request, the server control of the webpage sets their default values. 2. The instances of the Page derived class submit themselves to the Response Buffer. 3. The server returns the response to the client, the client renders and generates Form forms or other HTML elements. 4. You can click the Submit button to send a Post request to the server, and Submit the Form values to the server. 5. ASP. NET derived class to create a new instance, which processes the Post request and passes the body part of the Post request to the webpage, restore the status of the server control. 6. The Page derived class extracts variables from the Post body and uses the values of these variables to initialize the corresponding data or variables in the class. Next, the Page derived class generates itself, and the server control generates itself with the current content. 7. The customer receives the Post Request Response and generates controls using their current status. 2. The reason why ViewStateWeb forms can be kept in a state is the existence of ViewState. The HTML generated when a webpage is requested for the first time contains a hidden element (called _ VIEWSTATE ), the value of this element is a base64 encoded string used as the status repository of the webpage. When a webpage sends a request to the server, the server extracts the element value from the hidden _ VIEWSTATE field, and writes the latest value to _ VIEWSTATE when the server returns the webpage. 3. Web pages are short-lived, and the elements are the same. The purpose of creating a webpage is to process a request. Once the request is complete, the webpage is discarded. That is to say, each request is processed by a new instance of the Page class. If a webpage is created and a service request is prepared, a specific event sequence is generated, as follows: all server code marked in <%> must be added to the Page class Render method. The server control has submitted itself to the response buffer. 4. root path reference syntax many server-side controls contain URL attributes. For URL attributes of the server-side controls, you can use "~" To reference the root path of the directory to avoid the relative path in the hardcoded program directory. The symbol is resolved to the reference of Request. ApplicationPath. This symbol is only useful to the server control and is invalid for common HTML elements.

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.