Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Newbie Q: Using the session state object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ant - 20 Dec 2007 04:06 GMT
Hi,

I'm experimenting with the session state to see how it works. I'm trying to
increment with every page load. When I try to do this, I get an error
indicating that the page state object is either null or not instantiated. I
can't seem to get around this.
Below is the code I'm using:

Page.Session["MyInc"] = Int32.Parse((Page.Session["MyInc"].ToString()))+1;
labelOP.Text = Page.Session["MyInc"].ToString();

It's ok when I build, just when I run do I get the error.

Why does this not work?

Many thanks for helping me understand how to use this correctly
Ant
Manish - 20 Dec 2007 05:02 GMT
You would need to assign the value to Session variable in the Session_start
event in the Global.asax like below:

 Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
       ' Code that runs when a new session is started
           Session("test") = 1234
   End Sub

Then you can increment the value of the Session in the Page Load event
whenever it postbacks.

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
       Dim intValue As Integer
       intValue = CInt(Session("test"))
       intValue += 1
       Session("test") = intValue.ToString()
       Response.Write(Session("test"))
   End Sub

Regards,
Manish
www.componentone.com

> Hi,
>
[quoted text clipped - 13 lines]
> Many thanks for helping me understand how to use this correctly
> Ant

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.