• Asp.net在页面间传递大量数据(数据表)建议采用的方法


    能让数据在 两个不同站点之间传递吗? 我现在是想A站点的数据 传递到B站点....... 

    建议使用Cache 
    (1)不太影响程序性能不太可能,你都说了,是大量数据。我举个例子,你是从A.aspx传到B.aspx。那么如果有两个用户都会访问A,那你的数据是否要做到不会影响到不同的客户端?如果是这样的话,那么你存储的地方势必不能用Cache(不是绝对不能用,但是你必须区分客户端,你要做的工作更多),只能用Session, Cookies, ViewState, QueryString, Form等方法。 

    第二个条件:如果不止一个页面要做这个操作,比如A.aspx和B.aspx都需要传递“大量数据”给C.aspx,那么你如果存在Session里,又不能使之互相覆盖。所以如果是少量数据,比如只是一个数字,那么用ViewState, QueryString, Form都可以,只是他们需要多一趟往返于服务器和客户端。而象你这样大量数据的话,QueryString估计是不能用了。而ViewState其实也是Form。你可以考虑一下实际情况选择具体合用的方法。 

    (2)使用Server.Transfer方法 
    这个才可以说是面象对象开发所使用的方法,其使用Server.Transfer方法把流程从当前页面引导到另一个页面中,新的页面使用前一个页面的应答流,所以这个方法是完全面象对象的,简洁有效。下面这个代码是展示在需要很多个参数的时候,使用的方法,如果参数比较少就没必要使用这个方法了. 

    如果让所有的查询页面都继承一个接口,在该接口中定义一个方法,该方法的唯一作用就是让结果页面获得构建结果时所需的参数,就可实现多页面共享一个结果页面操作! 
    1、先定义一个类,用该类放置所有查询参数: 

    /**//// <summary> 
    /// 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、接口定义: 

    /**//// <summary > 
    /// 定义查询接口。 
    /// </summary > 
    public interface IQueryParams 

    /**//// <summary > 
    /// 参数 
    /// </summary > 
    QueryParams Parameters { get;} 

    3、查询页面继承IQueryParams接口(QueryPage.aspx): 

    <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 

    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) 

    //赋值 
    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、接收页面(ResultPage.aspx): 

    public partial class ResultPage : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 

    QueryParams queryParams = new QueryParams(); 
    IQueryParams queryInterface; 
    //实现该接口的页面 
    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); 

  • 相关阅读:
    如何删除PHP数组中的元素,并且索引重排(unset,array_splice)?
    Windows下,MySQL root用户忘记密码解决方案
    MySQL 5.5开启慢查询功能
    MySQL Cluster导入数据表时报错:Got error 708 'No more attribute metadata records (increase MaxNoOfAttributes)' from NDBCLUSTER
    MySQL Cluster在线添加数据节点
    关闭Linux防火墙(iptables) 及 SELinux
    MySQL Cluster 7.3.5 集群配置实例(入门篇)
    磁盘爆满导致MySQL无法启动:Disk is full writing './mysql-bin.~rec~' (Errcode: 28). Waiting for someone to free space...
    cocos2dx 3.1创建工 mac
    跟我一起学extjs5(05--主界面上增加顶部和底部区域)
  • 原文地址:https://www.cnblogs.com/sjqq/p/6513109.html
Copyright © 2020-2023  润新知