Introduction to Asp. net response objects and request objects

  • 2020-12-13 18:56:22
  • OfStack

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

Redirect: Redirects the client to the specified URL.

Write: Writes out the specified string.

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

form: Gets the value of a form element from a form that uses post submission.

querystring: Retrieves the value of a variable in the query string for forms submitted by get.

Consider an example: a landing page and a home page. When the login page login successfully, it will automatically jump to the main page.

1.login.aspx

 
<form id="form1" runat="server" method="post" >
<div>
<div>
<asp:Label ID="lbluser" runat="server" Text=" The user name "></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=" The login " OnClick="Button1_Click" style="width: 40px" />
</div>
</div>
</form>

login.aspx.cs
 
protected void Button1_Click(object sender, EventArgs e)
{
string user = Request.Form.Get("txtuser").ToString();// The client sends the user name that the server needs to submit
string pwd = Request.Form.Get("txtpwd").ToString(); // The client sends the password to the server
if (user == "1" && pwd == "1")
{
Response.Redirect("main.aspx?user=" + user); // Skip to the main page
}
else
{
Response.Write(" Login failed ");
}

2.main.aspx.cs
 
protected void Page_Load(object sender, EventArgs e)
{
string user = Request.QueryString["user"].ToString();// To obtain user The user name
Response.Write(" welcome " + user + " The login ");
}

When the login page gets the correct user name and password, the password will be redirected to the main page, which will also prompt for successful login. When the input error, there will be a login failure prompt.

In making brisket news release system, these two objects will be often used, I believe that in the future study will be used more, understanding will be more profound.


Related articles: