RegisterHiddenField() Not Updating After PostBack

Discussion in 'ASP .Net' started by Pete Mahoney, Jul 30, 2004.

  1. Pete Mahoney

    Pete Mahoney Guest

    I have a datagrid with a button column that displays some partner
    info. i.e. PartnerId, PartnerName ... The button column has a button
    that when the user clicks it they are redirected or server.transfer to
    a different page where I would like to pass the PartnerId. I could do
    this very easy with a QueryString, but would rather not display this
    info in the URL. I want to pass this by creating a form variable
    using the RegisterHiddenField() function.

    i.e.
    Private Sub PartnerGrid_ItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
    PartnerGrid.ItemCommand
    RegisterHiddenField("PartnerID", _
    PartnerGrid.DataKeys(e.Item.ItemIndex)
    If e.CommandName.ToString() = "Preview" Then
    'Server.Transfer("Somewhere")
    End If
    End Sub

    Now the problem here is when I call the RegisterHiddenField() the page
    is not Posted again before the Server.Transfer so the value of
    "PartnerId" is never updated. How do I repost this page so this value
    is updated before I Server.Transfer?
    Pete Mahoney, Jul 30, 2004
    #1
    1. Advertising

  2. Pete,

    There is a better way.

    If you add your value to the page context object it will be passed to the
    new page on server.transfer.

    Do so like this:

    Context.Items.Add("PartnerId", e.Item.ItemIndex)

    Server.Transfer("Somewhere")

    '---Retrieve the value on the next page...
    Dim ItemIndex As Int32 = CType(Context.Items.Item("PartnerId"), Int32)

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Pete Mahoney" <> wrote in message
    news:...
    > I have a datagrid with a button column that displays some partner
    > info. i.e. PartnerId, PartnerName ... The button column has a button
    > that when the user clicks it they are redirected or server.transfer to
    > a different page where I would like to pass the PartnerId. I could do
    > this very easy with a QueryString, but would rather not display this
    > info in the URL. I want to pass this by creating a form variable
    > using the RegisterHiddenField() function.
    >
    > i.e.
    > Private Sub PartnerGrid_ItemCommand(ByVal source As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
    > PartnerGrid.ItemCommand
    > RegisterHiddenField("PartnerID", _
    > PartnerGrid.DataKeys(e.Item.ItemIndex)
    > If e.CommandName.ToString() = "Preview" Then
    > 'Server.Transfer("Somewhere")
    > End If
    > End Sub
    >
    > Now the problem here is when I call the RegisterHiddenField() the page
    > is not Posted again before the Server.Transfer so the value of
    > "PartnerId" is never updated. How do I repost this page so this value
    > is updated before I Server.Transfer?
    S. Justin Gengo, Jul 31, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew Wieder
    Replies:
    1
    Views:
    360
    Yan-Hong Huang[MSFT]
    Jul 22, 2003
  2. MeDhanush
    Replies:
    1
    Views:
    891
    Natty Gur
    Aug 28, 2003
  3. Kevin Spencer

    RegisterHiddenField and trace

    Kevin Spencer, Oct 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,060
    Erik Cruz
    Oct 22, 2003
  4. Francis
    Replies:
    0
    Views:
    656
    Francis
    Nov 3, 2003
  5. =?Utf-8?B?RGF2ZQ==?=

    Page.RegisterHiddenField does not work!

    =?Utf-8?B?RGF2ZQ==?=, Jun 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    639
    =?Utf-8?B?RGF2ZQ==?=
    Jun 2, 2004
Loading...

Share This Page