Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-08
6
Medium Priority
?
217 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
  • 2
4 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

569 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