Transfering data from page to page

S

Shahid Juma

Hi,

This may be a very trivial answer but I was wondering if it possible to
have a ASP.NET page and on a user click, it transfers to another page.
Rather than redirecting to the new page, I want to pass some data with
it. I know I can do it using sessions but is it possible doing it in a
different way.

Thanks in advance,
Shahid
 
S

S. Justin Gengo

Shahid,

There are a few different methods depending on what type/length of data you
want to pass to the new page.

One of the simplest is to add the data to the Page.Context object like this:

Page 1:

Dim StringToTransfer As String = "My value to transfer (this could be any
type of object)"
Page.Context.Items.Add("MyKey", StringToTransfer)

Server.Transfer("page2.aspx")

Page 2:

Dim TransferredString As String = Ctype(Page.Context.Items.Item("MyKey"),
String)

Of course it would be more efficient to type the string with:
Page.Context.Items.Item("MyKey").ToString, but I wanted to show that any
object type could be passed within the context object.

One interesting possible drawback to this system is that page two gets
delivered to the client machine without the client receiving a redirect, so
the client's address will still read page1.aspx. Most of the time this isn't
an issue.


--
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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top