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