Summary of passing parameter methods between ASP. NET pages

Source: Internet
Author: User

Before writing, assume that the first page is send. aspx, and the second page is receive. aspx.
1. pass through URL link address
(1) Send. asp Code Copy code The Code is as follows: protected void button#click (Object sender, eventargs E)
{
Request. Redirect ("default2.aspx? Username = honge ");
}

(2) receive. aspx codeCopy codeThe Code is as follows: String username = request. querystring ["username"]; // you can obtain the parameter value.

2. Post Transmission
(1) Send. ASP codeCopy codeThe Code is as follows: <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 codeCopy codeThe Code is as follows: String username = ruquest. Form ["receive"];

3. Session Transmission
(1) Send. ASP codeCopy codeThe Code is as follows: protected void button#click (Object sender, eventargs E)
{
Session ["username"] = "honge ";
Request. Redirect ("default2.aspx ");
}

(2) receive. aspx codeCopy codeThe Code is as follows: String username = session ["username"]; // you can obtain the parameter value.

4. Application-Based Transmission
(1) Send. ASP codeCopy codeThe Code is as follows: protected void button#click (Object sender, eventargs E)
{
Application ["username"] = "honge ";
Request. Redirect ("default2.aspx ");
}

(2) receive. aspx codeCopy codeThe Code is as follows: String username = application ["username"]; To obtain the parameter value.

5. Use server. Transfer for Transmission
(1) Send. ASP codeCopy codeThe Code is as follows: public string name
{
Get {
Return "honge ";
}
}
Protected void button#click (Object sender, eventargs E)
{
Server. Transfer ("default2.aspx ");
}

(2) receive. aspx Code copy Code the code is as follows: send d = context. handler as send;
If (D! = NULL)
{< br> response. Write (D. Name); // you can obtain the parameter value.
}

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.