Saturday, March 24, 2012

Passing Variables Between Pages

I have a problem passing information between pages.

I have a page (SendingPage.aspx) that uses the DataReader to gather data from an Access Database and populates a label with the created variable.
<asp:Label id="lbl1" runat="server" text="<%# streetNuml %
This works just fine.

I then want to pass the data in 'lbl1" to another page (ReceivingPage.aspx) on a button click using

httpContext.Current.Items.Add( "StreetNumu", lbl1.text)
Server.Transfer("ReceivingPage.aspx")

and populate a text box

textbox1.text = HttpContext.Current.Items( "StreetNum" )

but it does work. Blank textbox.

Any help or a solution would be greatly appreciated. Thanks DylanTry using the Server.Transfer method overload that preserves the form variables.

Server.Transfer("blah.aspx", True)
I don't believe this will work even with the preserveForm parameter set to true.

Server.Transfer only preserves the Forms and QueryString collection which is read-only on the server-side. So it is not possible to add something to the collection so that the destination page will be able to reference it.

In this case it might be better to use a simple Response.Redirect with a querystring in order to pass the value.

hope this helps,
sivilian
Thank You for the replies. I've tried both techniques mentioned.

I think the main question, and I've realized this recently, is how to convert a
dynamic variable <%# ...... %> to a static variable that is not associated with the value provided by the database. I think this is possible, but how? Any thoughts.... Thanks again.

Cheers

Dylan

0 comments:

Post a Comment