RegisterHiddenField() Not Updating After PostBack

P

Pete Mahoney

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

S. Justin Gengo

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top