Talk about the use of the two objects, request and response

Source: Internet
Author: User


Asp. NET objects are as follows:

This article discusses the use of both the Request and Response objects from the "ASP. Form submit to background instance " from "net".

(i) Introduction of examples

form codes in the front desk <body>:

<body> <form method= "Get" action= "WebForm1.aspx" > <table S Tyle= "width:50%;" > <tr> <td> </td> <td> <input ID            = "Text1" name= "txtUserName" type= "text"/></td> <td class= "Auto-style1" > </td>                    </tr> <tr> <td> </td> <td> <input id= "Text2" name= "txtuserpwd" type= "text"/></td> <td class= "Auto-style1" > </td                    > </tr> <tr> <td> </td> <td> <input id= "CCC" type= "submit" value= "commit"/></td> <td class= "Auto-style1" > < /TD> </tr> </table> </form></body> 

Method in the form , which is how the form is submitted.

The action method in the form that specifies the submission target for the form.

Action= "WebFrom1", which refers to a form that is submitted after it is pointed to WebForm1. In the page of this path, the data of the Post method can be accepted with Request.from. get data can be accepted with requet.queststring. Use post or get, which can be set in the method property in the form.

C # code behind the scenes:

    Public partial class WebForm1:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e)            {//request Three ways to get the form is worth it. #region//string userName = Request.Form.Get ("txtUserName") for the Get value method of the Post method submission form.            ToString (); String userpwd = Request.Form.Get ("Txtuserpwd").            ToString (); #endregion #region//string userName = request.querystring["txtUserName" for the Get method to submit a form              ToString (); String userpwd = request.querystring["Txtuserpwd"].            ToString (); #endregion #region methods that apply to both methods, use the index value of reuqest to get the required form value string userName = request["Txtuse Rname "].            ToString (); String userpwd = request["Txtuserpwd"].            ToString ();            #endregion Response.Write ("Login username:" + userName + "; Password:" + userpwd);            if (username== "a" &&userpwd== "B") {Response.Redirect ("webform2.aspx"); }           else {Response.Redirect ("login.html"); }               }    }

(ii) Summary of usage of request object and Response object

first, the request object :

Request three a specific implementation of the method to get the form, I have written to the descendant code of the instance, here do not repeat.

Note here:the difference between the Get and post methods is as follows:

Get method commits, directly define a URL can be passed value. The disadvantage is that the passed value is shown in plaintext. Because the browser displays characters that are of a length, his data is restricted when displayed.

Post submission is to submit the data as an entire collection, and the parameters passed for the Post method will not be displayed in the URL with a plaintext.

Second, Response object

Response objects, the most important methods used are respone.write (string) and Responst.redirect (URL).

The role of Response.Write (string) is to return data (write data) from the server side to the client.

The role of Response.rediec ("url") is to orient another Web page end multiplicity the server.

"Recommended"

1. summarize the use instance of the Request object for ASP .

2. share a Request object small case

3. sharing the Request object in ASP five methods to obtain client data

4. request for an explanation of the ASP system object

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.