Sample Code for passing parameters between five ASP. NET pages

Source: Internet
Author: User
This document assumes that the first page is send. aspx, and the second page is receive. aspx.
1. pass through URL link address
(1) send. asp code
Protected void button#click (object sender, EventArgs e)
{
Request. Redirect ("Default2.aspx? Username = honge ");
}

(2) receive. aspx code

String username = Request. QueryString ["username"]; // you can obtain the parameter value.

2. POST Transmission
(1) send. asp code

<Form id = "form1" runat = "server" action = "receive. aspx" method = post>
<Div>
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "Button"/>
<Asp: TextBox ID = "username" runat = "server"> </asp: TextBox>
</Div>
</Form>

(2) receive. aspx code

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

3. Session Transmission
(1) send. asp code

Protected void button#click (object sender, EventArgs e)
{
Session ["username"] = "honge ";
Request. Redirect ("Default2.aspx ");
}

(2) receive. aspx code

String username = Session ["username"]; // you can obtain the parameter value.

4. Application-Based Transmission
(1) send. asp code

Protected void button#click (object sender, EventArgs e)
{
Application ["username"] = "honge ";
Request. Redirect ("Default2.aspx ");
}

(2) receive. aspx code

String username = Application ["username"]; To obtain the parameter value.

5. Use Server. Transfer for Transmission
(1) send. asp code

Public string Name
{
Get {
Return "honge ";
}
}
Protected void button#click (object sender, EventArgs e)
{
Server. Transfer ("Default2.aspx ");
}

(2) receive. aspx code

Send d = Context. Handler as send;
If (d! = Null)
{
Response. Write (d. Name); // you can obtain the parameter value.
}
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.