variables between pages

J

Jason

Hi, I am new to asp.net, and here is my question:

when a user logged into a web site, then I will pull his/her name (for example)
from database, then not matter which page he/she viewed, alwasy has his/her name
displayed somewhere at those pages? Some demo code?

Thanks in advance.

ASP.NET Rookie.
 
K

Karl

Jason, the long answer to your question is:
There are 5 common state mechanism in ASP.Net which mostly vary in terms of
lifetime and scope (with some exceptions). All are very useful when used at
the right time, they are:

Application - global to all users, exist for the lifetime of the application
Cache - global to all users, exists for the lifetime of the cache duration
Session - specific to each user, exist for the lifetime of the session
timeout
Viewstate - specific to each request, exists for the lifetime of a request
and its postback
Context - specific to each request, exists for the lifetime of the request.

What you want is a sessision (or something which shares its properties such
as a cookie) because (a) the information displayed is specific to each user
(b) the lifetime of the information is as long as the user visits the site.

Here's a very basic example:

Page1.aspx -->
<script runat="server" language="vb">
Sub Page_Load
Session.Add("Name", "Jason")
End Sub
</script>

<a href="page2.aspx">page 2</a>


Page2.aspx -->
<script runat="server" language="vb">
Sub Page_Load
name.Text = cstr(session("Name"))
End Sub
</script>

<asp:literal id="name" runat="server" />
 

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,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top