Because some parameters need to be passed between two pages in the project, the following methods for passing parameters are summarized:
Method 1:
Pass through URL link address
Send. aspx:
Copy the Code as follows:
Protected void button#click (Object sender, eventargs E)
{
Request. Redirect ("default2.aspx? Username = honge ");
}
Receive. aspx:
Copy the Code as follows:
String username = request. querystring ["username"]; To obtain the parameter value.
Method 2:
Send. aspx
Copy the Code 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>
Receive. aspx
Copy the Code as follows:
String username = ruquest. Form ["receive"];
Method 3:
Send. aspx:
Copy the Code as follows:
Protected void button#click (Object sender, eventargs E)
{
Session ["username"] = "honge ";
Request. Redirect ("default2.aspx ");
}
\ Receive. aspx:
Copy the Code as follows:
String username = session ["username"]; To obtain the parameter value.
Method 4:
Send. aspx:
Copy the Code as follows:
Protected void button#click (Object sender, eventargs E)
{
Application ["username"] = "honge ";
Request. Redirect ("default2.aspx ");
}
Receive. aspx:
Copy the Code as follows:
String username = application ["username"]; To obtain the parameter value.
Method 5:
Send. aspx:
Copy the Code as follows:
Public string name
{
Get {
Return "honge ";
}
}
Protected void button#click (Object sender, eventargs E)
{
Server. Transfer ("default2.aspx ");
}
Receive. aspx:
Copy the Code as follows:
Send d = context. handler as send;
If (D! = NULL)
{
Response. Write (D. Name); to obtain the parameter value.
}
In Asp.net 2.0, you can use the following method:
Copy the Code as follows:
Previouspage d = context. handler as previouspage;
If (D! = NULL)
{
Response. Write (D. Name); to obtain the parameter value.
}
It can also be used as follows:
Send. aspx:
Copy the Code as follows:
<Asp: button id = "btnsubmit" runat = "server" postbackurl = "~ /Reveive. aspx "text =" Submit "/>
Receive. aspx:
Copy the Code as follows:
<% @ Previouspagetype virtualpath = "~ /Default. aspx "%>
String name = previouspage. Name; to obtain the parameter value.
Supplement: In data binding controls such as datalist and repeater
<A href = "article. aspx? Id = <% # databinder. eval (container. dataitem, "article_id") %> "target =" _ blank "> // go to the link page and upload the parameter ID. The ID is the field in the database;
}
Receive. aspx:
Copy the Code as follows:
String username = application ["username"]; To obtain the parameter value.
Method 5:
Send. aspx:
Copy the Code as follows:
Public string name
{
Get {
Return "honge ";
}
}
Protected void button#click (Object sender, eventargs E)
{
Server. Transfer ("default2.aspx ");
}
Receive. aspx:
Copy the Code as follows:
Send d = context. handler as send;
If (D! = NULL)
{
Response. Write (D. Name); to obtain the parameter value.
}
In Asp.net 2.0, you can use the following method:
Copy the Code as follows:
Previouspage d = context. handler as previouspage;
If (D! = NULL)
{
Response. Write (D. Name); to obtain the parameter value.
}
It can also be used as follows:
Send. aspx:
Copy the Code as follows:
<Asp: button id = "btnsubmit" runat = "server" postbackurl = "~ /Reveive. aspx "text =" Submit "/>
Receive. aspx:
Copy the Code as follows:
<% @ Previouspagetype virtualpath = "~ /Default. aspx "%>
String name = previouspage. Name; to obtain the parameter value.
Supplement: In data binding controls such as datalist and repeater
<A href = "article. aspx? Id = <% # databinder. eval (container. dataitem, "article_id") %> "target =" _ blank "> // go to the link page and upload the parameter ID. The ID is the field in the database;