How to pass a parameter between pages?

S

Spongebob

Hello, I have a question about how to pass information between pages in

ASP.NET. There are 2 pages : page1.aspx, page2.aspx.
On page1 user clicks the record. Then, I need to show the detailed info

about that record in page2. How to pass the ID of record? Should I use

querystring or cookies or session variable?

The problem is:
1. I don't want to use query string at all :^(

2. There is no need to create the cookie or session variable for a

certain time, I only want to pass the int number from page1 to page2. :^(

3. It seems to me that the best way to solve that is to pass number via

page header. I use this sintax: :^(

in page1:
Response.AppendHeader("recordID","123");
Response.Redirect("page2.aspx");

in page2 on page load event:
Label1.Text=Request.Headers["recordID"].ToString(); //oh... :=(

But that doesn't work. May be wrong caching parameters? I've tried to set

Response.Cache.SetCacheability(HttpCacheability.NoCache), but that didn't

work too.

4. I think other suggested methods are too resource-expensive, why don't

use headers?

Oh, could somebody please explain me how to solve the situation?

Thanks a lot for Your attention and reading my message :^)

Andriy
 
C

Chad Z. Hower aka Kudzu

(e-mail address removed) (Spongebob) wrote in
The problem is:
1. I don't want to use query string at all :^(

No, that would be bad. You need to minimize the data you pass about.
3. It seems to me that the best way to solve that is to pass number via

page header. I use this sintax: :^(

in page1:
Response.AppendHeader("recordID","123");
Response.Redirect("page2.aspx");

Pass it in the URL. Something like:
Response.Redirect("page2.aspx?RecordID=123");



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
H

Hermit Dave

lol... well the reason why i ignored the post was that he did not want to
use query string.
he didnot want to use session...
well mate.. wait for asp.net 2.0.. you have cross page posting when you can
post from one aspx page to another without resorting to query string or
session
btw.. session isnt so bad... you can always set it to nothing after you are
done reading it.
 
C

Chad Z. Hower aka Kudzu

Hermit Dave said:
lol... well the reason why i ignored the post was that he did not want
to use query string.

Sorry, when I read query I thought SQL. I didnt understand that he meant the
GET / URL string.
well mate.. wait for asp.net 2.0.. you have cross page posting when you
can post from one aspx page to another without resorting to query string
or session

How does this work exactly in asp.net 2?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
H

Hermit Dave

well in 2.0 you have a new feature which allows you to post to a different
aspx page.
you have something called previouspage (within the page that received the
post) which is used to partially instantiate the aspx class (that caused the
post to the second aspx class or page however you put it).
once it is partially instantiated.. you can read the variables within the
instance.
 
C

Chad Z. Hower aka Kudzu

Hermit Dave said:
well in 2.0 you have a new feature which allows you to post to a
different aspx page.
you have something called previouspage (within the page that received
the post) which is used to partially instantiate the aspx class (that
caused the post to the second aspx class or page however you put it).
once it is partially instantiated.. you can read the variables within
the instance.

So if I understand you it works this way:

On post an event in the new page is fired.

From this event I can access the variables from the last page.

But I have to read all the variables - ie it elimiates postback type things
correct?

So its very simlilar to what we have now, you are just defining where to go
before hand, and the event is fired on that page instead.

Is this correct?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
H

Hermit Dave

yeap but the page has to be within the same application right now
http://weblogs.asp.net/pwilson/archive/2003/10/29/34597.aspx

you create a partial instance of posting class in the in the page that
received the post..
yes but right now you dont have a way of posting it to anothe page... unless
you put them in a query string and do a response.redirect. or put them in
session so that the other page you call can read it..
 
S

Spongebob

asp.net 2 must be cool :~)

The reason why I didn't want to use session is also that it expires
very soon on my system :=(
 

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,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top