Q: move between pages

G

Guest

Hello,
What is the best way to move from aspx page to aspx page by passing
variables. I was using session variables with Response.Redirectin both ways,
it may not be the right way. Users click a button in the current page and I
need pass a variable to use in the second page and when user click close I
need to jump back to first page. How can I do this? Can you give me exaple
please?
Thanks,
Jim.
 
B

Brock Allen

A QueryString works well:

<a href="Page2?SomeParam=5">Go to page 2</a>

and in Page2.aspx's Page_Load:

string val = Request.QueryString["SomeParam"];
 
B

Brock Allen

Oops, sloppy post -- Juan's gonna be all over me ;)
<a href="Page2?SomeParam=5">Go to page 2</a>

Should have been (note .aspx added):

<a href="Page2.aspx?SomeParam=5">Go to page 2</a>
 
G

Guest

Thanks for the reply. all these htlm confuses me. can I handle it code
behind? can you give me a site that has query string example.
 
S

Steve C. Orr [MVP, MCSD]

Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetbips.com/displayarticle.aspx?id=79
 
G

Guest

Hello,
I have;
string strName = this.Context.Items["name"].ToString();
in page_load in WebForm2.aspx. It works fine when loading, I need to close
this page and return back to first page so I have a close button with
Response.Redirect("MyPage.aspx");
When I click I get “Object reference not set to an instance of an object.â€
at tle line I mentioned above. What should I do?
Thanks,
Jim.
 
S

Steve C. Orr [MVP, MCSD]

Try ignoring the error or playing with the 2nd (endResponse) parameter as
documented here:
http://msdn.microsoft.com/library/d...fsystemwebhttpresponseclassredirecttopic2.asp




JIM.H. said:
Hello,
I have;
string strName = this.Context.Items["name"].ToString();
in page_load in WebForm2.aspx. It works fine when loading, I need to close
this page and return back to first page so I have a close button with
Response.Redirect("MyPage.aspx");
When I click I get "Object reference not set to an instance of an object."
at tle line I mentioned above. What should I do?
Thanks,
Jim.


Steve C. Orr said:
Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page,
etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetbips.com/displayarticle.aspx?id=79
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top