?
Solved

how can i pass a variable from page to page in asp.NET?

Posted on 2003-03-08
6
Medium Priority
?
213 Views
Last Modified: 2010-04-15
hey,

i just need to fill the variable on 1 page then make it available to another with the value stored, how can this be done?

regards,
das
0
Comment
Question by:DasmunchenC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 8098606
As long as the variable is public, you should be able to see it from your other form.
0
 
LVL 1

Accepted Solution

by:
Pickle earned 160 total points
ID: 8099707
use the session object,
In your first page:

int myvar = 5;
Session["myvar"] = myvar;


In your second page:
int myvar = (int)Session["myvar"];


myvar will now equal 5.  This is an ok way to move variables between forms.  Another way is to use querystrings.

On your first page you have a link to the second page:
<a href="secondPage.aspx?myvar=5">click to see this item</a>

On your second page you look at the variable with the request object.
int myvar = int.Parse(Request["myvar"]);

myvar will now equal 5
just remember that Request variables always come back as strings.
0
 

Author Comment

by:DasmunchenC
ID: 8106465
thank you for youre help guys, most invaluable, The seesion variable worked like a dream, thank you for putting it in plain english:
regards,
dasmunchenC
0
 
LVL 1

Expert Comment

by:Pickle
ID: 8106486
please accept my comment as the answer if I helped :)

Thanx
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question