Showing posts with label creates. Show all posts
Showing posts with label creates. Show all posts

Saturday, March 31, 2012

Session var alternatives / best practices

Hello...
I've got a asp.net site that involves pulling a few
records out of a database at which point it creates an
object.
I'd like a way to persist this data across pages, but its
a little more than I'd like to stick in my view state.
I was curious if it was advisable to use session vars for
this... I'd just use Application, but seeing as it doesnt
automatically expire items out of that collection, its not
very viable.
I'd like to make changes to this object persisted across
postbacks, then ultimately persist back to database.
ThanksSession is fine in ASP.NET. You can also set up your own persistance
methodology with static (Shared in VB.NET) variables.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Weston Weems" wrote:

> Hello...
> I've got a asp.net site that involves pulling a few
> records out of a database at which point it creates an
> object.
> I'd like a way to persist this data across pages, but its
> a little more than I'd like to stick in my view state.
> I was curious if it was advisable to use session vars for
> this... I'd just use Application, but seeing as it doesnt
> automatically expire items out of that collection, its not
> very viable.
> I'd like to make changes to this object persisted across
> postbacks, then ultimately persist back to database.
> Thanks
>

Thursday, March 29, 2012

Session var alternatives / best practices

Hello...
I've got a asp.net site that involves pulling a few
records out of a database at which point it creates an
object.
I'd like a way to persist this data across pages, but its
a little more than I'd like to stick in my view state.
I was curious if it was advisable to use session vars for
this... I'd just use Application, but seeing as it doesnt
automatically expire items out of that collection, its not
very viable.
I'd like to make changes to this object persisted across
postbacks, then ultimately persist back to database.
ThanksSession is fine in ASP.NET. You can also set up your own persistance
methodology with static (Shared in VB.NET) variables.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Weston Weems" wrote:

> Hello...
> I've got a asp.net site that involves pulling a few
> records out of a database at which point it creates an
> object.
> I'd like a way to persist this data across pages, but its
> a little more than I'd like to stick in my view state.
> I was curious if it was advisable to use session vars for
> this... I'd just use Application, but seeing as it doesnt
> automatically expire items out of that collection, its not
> very viable.
> I'd like to make changes to this object persisted across
> postbacks, then ultimately persist back to database.
> Thanks
>

Session var alternatives / best practices

Hello...

I've got a asp.net site that involves pulling a few
records out of a database at which point it creates an
object.

I'd like a way to persist this data across pages, but its
a little more than I'd like to stick in my view state.

I was curious if it was advisable to use session vars for
this... I'd just use Application, but seeing as it doesnt
automatically expire items out of that collection, its not
very viable.

I'd like to make changes to this object persisted across
postbacks, then ultimately persist back to database.

ThanksSession is fine in ASP.NET. You can also set up your own persistance
methodology with static (Shared in VB.NET) variables.

--

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Weston Weems" wrote:

> Hello...
> I've got a asp.net site that involves pulling a few
> records out of a database at which point it creates an
> object.
> I'd like a way to persist this data across pages, but its
> a little more than I'd like to stick in my view state.
> I was curious if it was advisable to use session vars for
> this... I'd just use Application, but seeing as it doesnt
> automatically expire items out of that collection, its not
> very viable.
> I'd like to make changes to this object persisted across
> postbacks, then ultimately persist back to database.
> Thanks

Monday, March 26, 2012

Session variable in static method creates error.

Hi. I have a static method that adds a number to a session variable. But when I code a line like this:

Session["CartSubTotal"] = Convert.ToDouble(Session["CartSubTotal"]) + Price;

I get an error like this:

c:\inetpub\wwwroot\aaagolfballs\ShoppingCart.aspx.cs(235): An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.Session'

What is a guy to do?If Session["CartSubTotal"] has not been set, that is the error you get.

Check if Session["CartSubTotal"]==null, if so, just set it equal to price rather than trying to add in the existing value of the session variable...
It was null, but I put into the global.asax:


protected void Session_Start(Object sender, EventArgs e)
{
Session["CartSubTotal"] = 0;
}

I still get the same error.
I've got it. For those with the same error, here is how I fixed it. I used these variables in the static method:
System.Web.HttpContext.Current.Session
System.Web.HttpContext.Current.Server

Thanks to all.