asp.net the method of parameter value between page and page (post pass value and get pass value) _ Practical Tips

Source: Internet
Author: User

First, the use of post transmission value

Transfer Value ASP file send.aspx

Copy Code code as follows:

<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 ASP File receive.aspx

Copy Code code as follows:

String username = ruquest.form["Receive"];

One, get method pass value

QueryString is also called a query string, which is passed after the page address (URL) is appended to the data. such as page a.aspx jump to the page b.aspx, you can use Request.redirect ("b.aspx? parameter name = parameter value") method, you can also use hyperlinks:, page jump, in the target page to be available ruquest["parameter name" to receive parameters. The advantage of using the Querysting method 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, there is a risk of tampering, cannot pass the object, only the query string is feasible when the page is requested through the URL

The following code fragment demonstrates how to implement this method:

SOURCE page code:

Copy Code code as follows:

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:

Copy Code code as follows:

private void Page_Load (object sender, System.EventArgs e)
{
label1.text=request.querystring["Name"];
label2.text=request.querystring["email"];
}

Related Article

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.