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