Several Methods for passing parameters between ASP. NET pages

Source: Internet
Author: User

Several Methods for passing parameters between Asp.net pages

Method 1: pass through URL link
Send. aspx:
Protected void button#click (object sender, EventArgs e)
{
Request. Redirect ("Default2.aspx? Username = honge ");
}
Receive. aspx:
String username = Request. QueryString ["username"];
In this way, the parameter value is obtained.

Method 2: post
Send. aspx
<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>
Receive. aspxstring username = Ruquest. Form ["receive"];

Method 3: Use session
Send. aspx:
Protected void button#click (object sender, EventArgs e)
{
Session ["username"] = "honge ";
Request. Redirect ("Default2.aspx ");
}
Receive. aspx:
String username = Session ["username"];
In this way, the parameter value is obtained.

Method 4: Use Application
Send. aspx:
Protected void button#click (object sender, EventArgs e)
{
Application ["username"] = "honge ";
Request. Redirect ("Default2.aspx ");
}
Receive. aspx:
String username = Application ["username"];
In this way, the parameter value is obtained.

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

Receive. aspx:
Send d = Context. Handler as send;
If (d! = Null)
{
Response. Write (d. Name); to obtain the parameter value.
}

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next Page

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.