ASP.net response object and Request Object use Introduction _ Practical Skills

Source: Internet
Author: User

1.Response: The server sends the client information, or the server transmits the output to the user.

Redirect: Let the client redirect to the specified URL.

Write: Writes out the specified string.

2.request: The client sends the server, or obtains the information from the client.

Form: Gets the value of a form element from a form that uses the Post submission method.

QueryString: Retrieves the variable value from the query string and applies to the form of get submit.

Take an example: a landing page, there is a main page. When the landing page is successful, it automatically jumps to the main page.

1.login.aspx

Copy Code code as follows:

<form id= "Form1" runat= "Server" method= "POST" >
<div>
<div>
<asp:label id= "Lbluser" runat= "server" text= "username" ></asp:Label>
<asp:textbox id= "Txtuser" runat= "Server" ></asp:TextBox>
</div>
<div></div>
<div>
<asp:label id= "lblpwd" runat= "server" text= "password" ></asp:Label>
<asp:textbox id= "txtpwd" runat= "Server" ></asp:TextBox>
</div>
<div>
<asp:button id= "Button1" runat= "server" text= "login" onclick= "button1_click" style= "width:40px"/>
</div>
</div>
</form>

Login.aspx.cs
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
String user = Request.Form.Get ("Txtuser"). ToString ()//The client sends the server a user name to submit
string pwd = Request.Form.Get ("Txtpwd"). ToString (); The password the client sends the server to submit
if (user = = "1" && pwd = = "1")
{
Response.Redirect ("main.aspx?user=" + user); Jump to Main Page
}
Else
{
Response.Write ("Login Failed");
}

2.main.aspx.cs
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
String user = request.querystring["user"]. ToString ();//Get user username
Response.Write ("Welcome" + user + "login");
}

When the login page gets the correct username and password, the password jumps to the main page, and the home page prompts you for a successful login. When you enter an error, you will be prompted for a login failure.

Beef Brisket in the press release system, these two objects will often be used, I believe that in the future learning will be used more, the understanding will be more profound.

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.