asp. net page to page pass parameter values method of post pass values and get pass values

  • 2020-12-05 17:09:33
  • OfStack

1. Use POST to pass values

asp file send.aspx


<form id="form1" runat="server" action="receive.aspx" method=post>
    <div>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="username" runat="server"></asp:TextBox>
</div>
</form>

Accept the asp file receive.aspx


string username = Ruquest.Form["receive"];

1. get method value passing

QueryString, also known as a query string, is a method in which the data to be passed is appended to the web page address (URL). If the page A.aspx jumps to the page B.aspx, you can use Request.Redirect (" ES31en.aspx? Parameter name = parameter value ") method, can also be hyperlinked:, after the page jumps, Ruquest[" parameter name "] can be used in the target page to receive parameters. The advantage of using the QuerySting approach is that it is simple to implement and does not use server resources. The disadvantage is that the value passed is displayed in the browser's address bar, is at risk of tampering, cannot pass the object, and is only feasible if the page is requested via URL to query the string

The following code snippet demonstrates how to implement this method:

Source page code:


private void Button1_Click (object sender, System.EventArgs e)
{
   string url;
   url="anotherwebform.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text;
   Response.Redirect(url);
}

Target page code:


private void Page_Load(object sender, System.EventArgs e)
{
   Label1.Text=Request.QueryString["name"];
   Label2.Text=Request.QueryString["email"];
}


Related articles: