asp.net transfer of large amounts of data between pages (datasheet) Recommended method _ Practical skills

Source: Internet
Author: User
Can the data be passed between two different sites? Now I want to send the data of site A to the B site ....

Recommended use of cache
(1) Does not affect the performance of the program is not very likely, you have said, is a large number of data. Let me give you an example of how you passed from A.aspx to b.aspx. So if you have two users who will access a, will your data not affect different clients? If so, then you store the place will not be able to use cache (not absolutely not, but you have to distinguish the client, you have to do more work), can only use session, Cookies, ViewState, QueryString, form and other methods.

The second condition: if more than one page to do this operation, such as a.aspx and b.aspx need to pass "a lot of data" to c.aspx, then if you exist in the session, you can not make it cover each other. So if it's a small amount of data, like just a number, then you can use ViewState, QueryString, form, but they need one more trip to the server and the client. As with such a large amount of data as you, querystring estimate is not available. And viewstate is actually form. You can consider the actual situation to choose a specific method of sharing.

(2) Using Server.Transfer method
This can be said to be the object of the development of the method used, which uses the Server.Transfer method to guide the process from the current page to another page, the new page uses the previous page of the response stream, so this method is completely surface image object, concise and effective. The following code shows the method used when a lot of parameters are needed, and there is no need to use this method if the parameters are relatively small.

If you want all query pages to inherit an interface, define a method in the interface, the only function of this method is to let the results page to obtain the parameters required to build the results, you can achieve multiple pages sharing a result page operation!
1, first define a class, use this class to place all query parameters
Copy Code code as follows:

/**////<summary>
Summary description of Queryparams
</summary>
public class Queryparams
{
private string FirstName;
private string LastName;
private int age;
public string Firstname
{
get {return this.firstname;}
set {this.firstname = value;}
}
public string LastName
{
get {return this.lastname;}
set {this.lastname = value;}
}
public string Age
{
get {return this.age;}
set {this.age = value;}
}
}

2. Interface Definition
Copy Code code as follows:

/**////<summary >
Define the query interface.
</summary >
public interface Iqueryparams
{
/**////<summary >
Parameters
</summary >
Queryparams Parameters {get;}
}

3, Query page Inheritance Iqueryparams interface (querypage.aspx)
Querypage.aspx
Copy Code code as follows:

<form id= "Form1" runat= "Server" >
<div>
<asp:textbox id= "txtFirstName" runat= "Server" ></asp:TextBox>
<asp:textbox id= "Txtlastname" runat= "Server" ></asp:TextBox>
<asp:textbox id= "txtage" runat= "Server" ></asp:TextBox>
<asp:button id= "Btnenter" runat= "Server" text= "button" onclick= "Btnenter_click"/></div>
</form>

QueryPage.aspx.cs
Copy Code code as follows:

Public partial class QueryPage:System.Web.UI.Page, Iqueryparams
{
Private Queryparams Queryparams;
Public Queryparams Parameters
{
Get
{
return queryparams;
}
}
public void Btnenter_click (object sender, System.EventArgs e)
{
assigning values
Queryparams = new Queryparams ();
Queryparams.firstnname = This.txtFirstName.Text;
Queryparams.lastname = This.txtLastName.Text;
Queryparams.age = This.txtAge.Text;
Server.Transfer ("resultpage.aspx");
}
protected void Page_Load (object sender, EventArgs e)
{ }
}

4. Receiving page (resultpage.aspx)
ResultPage.aspx.cs
Copy Code code as follows:

Public partial class ResultPage:System.Web.UI.Page
{
Protected V OID Page_Load (object sender, EventArgs e)
{
Queryparams queryparams = new Queryparams ();
Iqueryparams QueryInterface;
//page that implements the interface
if (Context.Handler is Iqueryparams)
{
QueryInterface = (iqueryparams) Context.Handler;
Queryparams = queryinterface.parameters;
}
Response.Write ("FirstName:");
Response.Write (Queryparams.firstname);
Response.Write ("<br/>lastname:");
Response.Write (Queryparams.lastname);
Response.Write ("<br/>age:");
Response.Write (Queryparams.age);
}
}
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.