passing variables

  • Thread starter Thread starter Phil Barber
  • Start date Start date
P

Phil Barber

I have a login page (page1) on successful login I retrieve an employeeID
from a SQL Database.
then move to a 2nd page. What is the best way to get the EmployeeID from
Page 1 to Page2

I have had problems with global variables in the past concerning sessions.

thanks.

Phil Barber
 
I set mine into the
Page.User.Identity.Name
Then I always have the userID accessable across the app/site
 
It all depends on how you plan to navigate from Page 1 to Page 2. If, for
example, you are doing it on the server side, via Server.Transfer() you
could add the data to the current Page's HttpContext, and after transferring
(the HttpContext is transferred as well) reading it back out. If you are
navigating via hyperlink, you might want to pass it via QueryString (unless
there are security reasons to hide the data from the user). There are other
ways of navigating from one page to another; you need to determine the
method of tranferring the data based upon the method of navigation.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
When I try that it tells me that property is read - only!
any ideas.
thanks
Phil.
 
FYI -

Microsoft Knowledge Base Article - 307598
-----Original Message-----
If your volume is low or your host server is powerful,
you can store it in a session variable:
ex.

Session("EmpID") = row("EmployeeID")(note:from the
database)

Then extract back out the session variable and into your
logic where ever you need it on page 2.

lblEmpID.Text = Session("EmpID")

However, be careful if you have large volumes. If so
consider storing your session variables in a MSSQL
Database. If you are running the application over
multiple servers then you have to store your variables in
MSSQL or use another method of session variables as
session variables are stored in memory.

I would suggest you Search MSDN on Session Variables in
ASP.NET and it you will find your answers with guidelines
on how to approach Session variables with the best
approach.
the
EmployeeID from
.
 
Setting the form action attribute just isn't the ASP.NET way.

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.dotnetjunkies.com/tutorials.aspx?tutorialid=600

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

Here's one nice, simple way to pass values from one page to another:

'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)
 
Back
Top