But... (you knew there had to be a "but" otherwise I wouldn't be posting!)

I have a page called DocSelection that links to a page called DocList. These are currently in ASP and I am migrating them.

DocList needs access to DocSelection's variables. This was easily done in ASP. I did some research, found out this is also available in .NET 2.0 (the version I'm using, phew!) via some calls to Me.PreviousPage.FindControl().

So let's say there's a database key that's selected on DocSelection via dropdownlists and some checkboxes of what kind of documents the user wants displayed. The first time I populated my grid, I have all these varaibles because DocList was just called from DocSelection. Then I want to see my gridview sorted by Date in the other direction (is ascending, want descending). This causes a postback and I apparently can't use PreviousPage anymore to get the values of the variables I need to get my database data.

My gridview is sorting successfully right now in development because I have the data that I am losing hardcoded. How can I retain this data between postbacks to the second page?

This is the code that runs when I sort:
Code:
    Public Property GridViewSortDirection() As SortDirection

        Get
            If ViewState("sortDirection") Is Nothing Then
                ViewState("sortDirection") = SortDirection.Ascending
            End If

            Return DirectCast(ViewState("sortDirection"), SortDirection)
        End Get

        Set(ByVal value As SortDirection)
            ViewState("sortDirection") = value
        End Set
    End Property

    Protected Sub gvDocList_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvDocList.Sorting
        Dim sortExpression As String = e.SortExpression

        If GridViewSortDirection = SortDirection.Ascending Then

            GridViewSortDirection = SortDirection.Descending

            SortGridView(sortExpression, "DESC")
        Else
            GridViewSortDirection = SortDirection.Ascending

            SortGridView(sortExpression, "ASC")
        End If

    End Sub

    Private Sub SortGridView(ByVal sortExpression As String, ByVal direction As String)

        ' You can cache the DataTable for improving performance 

        ' Dim dt As DataTable = GetData().Tables(0)
        GetDataForGrid()
        Dim dt As DataTable = ds.Tables(0)

        Dim dv As New DataView(dt)

        dv.Sort = sortExpression + " " + direction

        gvDocList.DataSource = dv

        gvdoclist.DataBind()

    End Sub
Oh, I just noticed...If I took this code's author's advice about caching the data, I guess I wouldn't have to call the database again so that would solve the problem where I lose my variables, but how is the dataset cached? How can the dataset be retained during the postback?

Thanks.