Passing parameters on two pages)

Source: Internet
Author: User

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;

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.