Asp.net knowledge Summary

Source: Internet
Author: User

1. In the page_load event! Page. ispostback:

The page_load subprogram runs every time a page is loaded. If you only want to execute code in page_load when loading this page for the first time, you can use the page. ispostback attribute. If the page. ispostback attribute is false, the page is loaded for the first time. If it is true, the page is "Post" and returned to the server.


For example:

Protected void page_load (Object sender, eventargs e) {If (! Page. ispostback) {// determine whether the page is loaded for the first time. If the page is loaded for the first time, clear the text box this.txt username. TEXT = ""; this.txt userpwd. TEXT = "";}}

NOTE: If page. ispostback = false, the text box is cleared, indicating that the page is loaded for the first time.


Page. ispostback indicates whether to send back. the so-called sending-back means that after the page is loaded, the server is submitted on this page. page. ispostback = true indicates that the request is sent back. In response to the client request, page. ispostback = false, so the page is correctly applied. ispostback can greatly improve application performance.


Summary:

1) ispostback is only false when it is enabled for the first time, and true when it is used for other times.


2) during each page load, the code to be loaded each time is put in ispostback as needed, and the code to be loaded once is put in if (! Ispostback.


3) each time a user returns any server information, the ispostback attribute is triggered to determine whether the user has logged on or other events.


4) if there is no request value in the post method request, that is, request. if form = NULL, ispostback = false; if the get method does not contain a request value, that is, request. if querystring = NULL, ispostback = false.


5) in general, if the request does not have a request value, ispostback = false. If a request value does not include some special keys or values such as "_ viewstate", ispostback = false (after each request. net Framework will return some special hidden domain "_ viewstate" to the client ). There are also some special situations where the above rules cannot be correctly judged and need special processing, including server. transfer, response. redirect, crosspagepostback, server. execute, page element changes and re-compilation.


2. Difference between request and response

A request is a request sent by the client to the server, and a response is a message sent by the server to the client.

(1) attributes of the request object:

Form: Get the set of form variables defined on the webpage;

Querystring obtains the set of HTTP query string variables represented by name/value pairs. The variable value is displayed in the address bar, and the security cannot be guaranteed. Pass the control value in the Form to get the value using request. form, and the parameters passed in the address bar are obtained using request. querystring.


1>. Difference Between get and post:

Get gets data from the server, and post transfers data to the server.

Get is to add the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one and can be seen in the URL. Post is implemented through the httppost mechanism, place the fields and content in the form in the HTML header and send them to the URL address referred to by the Action attribute. You cannot see this process.

For the get method, the server uses request. querystring to obtain the value of the variable. For the POST method, the server uses request. Form to obtain the submitted data.

The data size transmitted by get is small and cannot exceed 2 kb. The amount of data transmitted by post is large, which is generally not restricted by default.

Get is very low in security, and post is highly secure. If it contains confidential information, it is recommended to use the post data submission method, but the execution efficiency is better than the POST method.

We recommend that you use the get Method for Data Query. When adding, modifying, or deleting data, we recommend that you use the POST method.

 

2> take the logon interface as an example:


A. Get Method

<Form method = "get" Action = "webform2.aspx"> <Table border = "0" style = "width: 100%; "> <tr> <TD> </TD> <input id =" text1 "name =" txtusername "type =" text "/> </TD> <TD> </TD> </tr> <TD class = "auto-style1"> </TD> <TD class = "auto-style1"> <input id = "text2" Name = "txtuserpwd" type = "text"/> </TD> <TD class = "auto-style1"> </TD> </tr> <TD> </TD> <TD> <input id = "submit1" type = "Submit" value = "Logon"/> </TD> </tr> </ table> </form>


Write Method for receiving data transmitted using the get method:

  protected void Page_Load(object sender, EventArgs e)        {                        string userName =Request.QueryString["txtUserName"].ToString();            string userPwd =Request.QueryString["txtUserPwd"].ToString();                        if (userName =="a"&&userPwd =="a")            {                Response .Redirect ("WebForm1.aspx?userName="+userName+"&userPwd="+userPwd);            }            else            {                Response.Redirect("login.html");            }        }


B. Post Method

<Form method = "Post" Action = "webform2.aspx"> <Table border = "0" style = "width: 100%; "> <tr> <TD> </TD> <input id =" text1 "name =" txtusername "type =" text "/> </TD> <TD> </TD> </tr> <TD class = "auto-style1"> </TD> <TD class = "auto-style1"> <input id = "text2" Name = "txtuserpwd" type = "text"/> </TD> <TD class = "auto-style1"> </TD> </tr> <TD> </TD> <TD> <input id = "submit1" type = "Submit" value = "Logon"/> </TD> </tr> </ table> </form>


Write Method for receiving data transmitted using the POST method:

protected void Page_Load(object sender, EventArgs e)        {            string userName = Request.Form.Get("txtUserName").ToString();            string userPwd = Request.Form.Get("txtUserPwd").ToString();                       if (userName =="a"&&userPwd =="a")            {                Response .Redirect ("WebForm1.aspx?userName="+userName+"&userPwd="+userPwd);            }            else            {                Response.Redirect("login.html");            }        }


(2) common response methods:

Write: used to write text to the current HTTP Response stream to make it part of the returned page;

Redirect: redirects users from the request page to another page.


3. Differences between HTML, htm, and XML

Both htm and HTML are static webpage file extensions. Htm comes from the era of DOS three-character file extensions, while HTML supports multi-character extensions in the Windows era.

XML is used to store data, focusing on the data itself. HTML is used to define data, focusing on the data display mode. XML is structured information that contains some content (such as text, images, and so on) and some labels that indicate the means to reproduce the content (for example, the information in the header of a chapter has different meanings from that in its footer .) All documents have different structures. A markup language defines the structure of a document. The XML specification defines a standard for marking documents.


Summary: ASP. NET is just the beginning. More knowledge is available for us to learn, and more treasures are waiting for us to explore.

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.