Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. server.transfer gridview DataKeys from 1st page to 2nd page, lost values on postback?

server.transfer gridview DataKeys from 1st page to 2nd page, lost values on postback?

Scheduled Pinned Locked Moved ASP.NET
questionsysadmindocker
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jake williamson
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups