server.transfer gridview DataKeys from 1st page to 2nd page, lost values on postback?
-
hey out there, this is driving me nuts! i'm trying to transfer a number of 'DataKeys' from one page to a second page. i can get the values to come across using 'Server.Transfer' but when a button on the receiving page is clicked (causing a postback), the url changes and i lose the values. how do i keep them?! it's a simple 'post page ones values to page two, perform a search on page two by clicking a button, select an option and go back to the 1st page' kinda thing. on my initial page i've a gridview: <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_onRowCommand" DataKeyNames="UserID,FirstName" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="userid" HeaderText="userid" />
<asp:BoundField DataField="firstname" HeaderText="firstname" />
asp:TemplateField
<ItemTemplate>
<asp:Button ID="btnSearchPage" runat="server" Text="Button" CommandName="gotoSearchPage" CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> and this is my 'OnRowCommand' command:Protected Sub GridView1_onRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) 'grab the row info Dim strCmdName As String = e.CommandName.ToString Dim intDataItemIndex As String = e.CommandArgument.ToString 'get the row details Context.Items("UserID") = GridView1.DataKeys(intDataItemIndex).Item("UserID") Context.Items("FirstName") = GridView1.DataKeys(intDataItemIndex).Item("FirstName") If (strCmdName = "gotoSearchPage") Then Server.Transfer("~/searchPage.aspx", True) End If End Sub
on my receiving page 'searchPage.aspx' i can get the DataKeys using this in the page init:Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init If (Not IsPostBack) Then intFacilityID = Context.Items("FacilityID") End If End Sub
but the moment i click the search button, the url changes and hey presto - no more data keys?! this must be possible?! any suggestions would be great, cheers, jake