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;