Link to home
Start Free TrialLog in
Avatar of luefher
luefherFlag for United States of America

asked on

How to preserve large data on postback without loading it again

Hello,

I have a page with a table in UpdatePanel that is dynamically populated with a large amount of data, takes some time to retrieve. The table has LinkButtons in it to drill-down on that data, which is then displayed in a hide/show div. Problem is, since it's a postback, the original data has to be retrieved again - I'm trying to avoid this since it takes time but it's the same data that was retrieved before postback - I just want to retrieve the drilled-down data and show it. If I put the retrieval of initial data in (!IsPostBack), then it, of course is not retrieved on postback and is not showed. Is there some kind of a workaround?
Thanks!
<asp:UpdatePanel ID="UpdatePanel" runat="server">
    <ContentTemplate>
        ...
        <asp:Table ID="TableData" runat="server">
        </asp:Table>
        <div id="...>
            <asp:Table ID="TableDrillDown" runat="server">
            </asp:Table>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
 
 
protected void Page_Load(object sender, EventArgs e)
{
    this.PopulateData();
}
 
private void PopulateData()
{
    // here we retrieve a large amount of data
    ...
    // then populate table
    ...
    // adding LinkButtons along the way
    TableRow tr = new TableRow();
    TableCell td = new TableCell();
    LinkButton lb = new LinkButton();
    lb.ID = linkButtonId;
    lb.Text = someDataValue;
    lb.CommandName = "drill-down";
    lb.CommandArgument = someArgs;
    lb.Command += this.LinkButton_DrillDownCommand;
    td.Controls.Add(lb);
    tr.Cells.Add(td);
    this.TableData.Rows.Add(tr);
    ...
}
 
protected void LinkButton_DrillDownCommand(object sender, CommandEventArgs e)
{
    // Populate drill-down table here
    TableRow tr = new TableRow();
    TableCell td = new TableCell();
    td.Text = someDataValue;
    tr.Cells.Add(td);
    this.TableData.Rows.Add(tr);
    ...
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of brawney
brawney
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use an ObjectDataSource and bind a repeater/grid to it then enable the in built caching :
http://www.asp.net/Learn/Data-Access/tutorial-58-vb.aspx
Avatar of luefher

ASKER

Our report table does not have a regular row-by-row structure (I would've used GridView otherwise) and then the data retrieved uses several ad-hoc queries... Haven't thought about session, though - I am fine with the users having to wait once in a while (when it expires). Still interested if there is a way to do without resorting to session, but session works in this case!
I've used the Enterprise Library caching block before too.  But in asp.net the application cache pretty much gives you the same thing without having to pull in the Enterprise Library.