Asp. NET is very useful for the method of passing values between pages

Source: Internet
Author: User
Tags object query return tostring

one, the current in the ASP.net page transfer value altogether has so several ways:
1. Form submission
<form action= "target.aspx" method = "POST" name = "Form1" >
<input name = "param1" value = "1111"/>
<input name = "param2" value = "2222"/>
</form>
....
Form1.submit ();
....
This kind of side in the ASP. NET is not valid because of ASP. NET form is always submitted to its own page, if you want to submit to another page, you need special treatment.
2, link address transmission
Receive page: string str = request["param1"]
3, session sharing
Send page: Session ("param1") = "1111";
Press Receive page String str = session ("param1"). ToString ();
4, Application sharing
Send page: Application ("param1") = "1111";
by page: string str = Application ("param1"). ToString ();
This method is not commonly used because application is shared across an application domain, and all users can change and set their values, so only use counters and so on where global variables are needed.
5. Cookies
6, Response.Redirect () way
Response.Redirect ("target.aspx?param1=1111¶m2=2222")
Receive page: string str = request["param1"]
7, Server.Transfer () way.
Server.Transfer ("target.aspx?param1=1111¶m2=2222")
Receive page: string str = request["param1"]

Two, if in two pages need a large number of parameters to pass transmission, such as data query, and other pages, with 1-6 of the method of transmission value and inconvenience, and the 7th method does have a unique advantage! However, this method requires a certain set of settings, now a brief description of how the method is used:
Take the query data page for example:
Set the following public properties (querypage.aspx) in the query page:

The following are the referenced contents:
public class QueryPage:System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtstadate;
protected System.Web.UI.WebControls.TextBox txtenddate;
...
<summary>
Start time
</summary>
public string Stadate
{
get{return this.txtStaDate.Text;}
Set{this.txtstadate.text = value;}
}
<summary>
End time
</summary>
public string EndDate
{
get{return this.txtEndDate.Text;}
Set{this.txtenddate.text = value;}
}
....
private void Btnenter_click (object sender, System.EventArgs e)
{
Server.Transfer ("resultpage.aspx");
}
}

In the Show Query results page (resultpage.aspx):

The following are the referenced contents:
public class ResultPage:System.Web.UI.Page
{
private void Page_Load (object sender, System.EventArgs e)
{

Convert to get the data entered in the previous page
Querypage querypage = (querypage) Context.Handler;

Response.Write ("Stadate:");
Response.Write (Querypage.stadate);
Response.Write ("<br/>enddate:");
Response.Write (Querypage.enddate);
}
}

Total 3 page: previous 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.