asp.net Transfer Parameter Method Summary _ Practical Tips

Source: Internet
Author: User
Before writing, assume that the first page is send.aspx and the second page is receive.aspx
1, through the URL link address delivery
(1) Send.asp code
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
Request.redirect ("Default2.aspx?username=honge");
}

(2) Receive.aspx code
Copy Code code as follows:

String username = request.querystring["username"];//so that the parameter values can be obtained.

2, Post mode transmission
(1) Send.asp code
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>

(2) Receive.aspx code
Copy Code code as follows:

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

3, Session mode transfer
(1) Send.asp code
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
session["username"] = "Honge";
Request.redirect ("default2.aspx");
}

(2) Receive.aspx code
Copy Code code as follows:

String username = session["username"];//so that the parameter values can be obtained.

4, Application way to pass
(1) Send.asp code
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
application["username"] = "Honge";
Request.redirect ("default2.aspx");
}

(2) Receive.aspx code
Copy Code code as follows:

String username = application["username"] so that the parameter values can be obtained.

5, the use of Server.Transfer for transmission
(1) Send.asp code
Copy Code code as follows:

public string Name
{
get {
return "Honge";
}
}
protected void Button1_Click (object sender, EventArgs e)
{
Server.Transfer ("default2.aspx");
}

(2) Receive.aspx code
Copy Code code as follows:

Send d = context.handler as send;
if (d!= null)
{
Response.Write (d.name);//This will get the parameter values.
}

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.