Connecting Tech Pros Worldwide Forums | Help | Site Map

An object reference is required for the non-static field, method, orproperty 'System.Web.UI.Page.Request.get'

jake
Guest
 
Posts: n/a
#1: Nov 21 '08
I think I may know why this is happening but I am a little fuzzy as to
what the solution should be as I am somewhat new to all of this.

The bare-bones code that generates the error upon compilation is:

class cart
{
public static string fetchCartCookieValue()
{
return Request.Cookies["cartCookie"].Value;
}


}

Any help is appreciated.
jake

DH
Guest
 
Posts: n/a
#2: Nov 21 '08

re: An object reference is required for the non-static field, method, orproperty 'System.Web.UI.Page.Request.get'


jake wrote:
Quote:
I think I may know why this is happening but I am a little fuzzy as to
what the solution should be as I am somewhat new to all of this.
>
The bare-bones code that generates the error upon compilation is:
>
class cart
{
public static string fetchCartCookieValue()
{
return Request.Cookies["cartCookie"].Value;
}
>
>
}
>
Any help is appreciated.
jake

Jake,

my guess would be you have not initialized Request and that Cookies is
not static.
If that is where the compile error is coming up that that would be your
problem.
jake
Guest
 
Posts: n/a
#3: Nov 21 '08

re: An object reference is required for the non-static field, method, orproperty 'System.Web.UI.Page.Request.get'


DH,
Yes I realize that that may well be true. But how may I code a static
method that can retrieve a cookie value?
jake


On Nov 21, 3:52*pm, DH <I.dont.n...@more.spamwrote:
Quote:
jake wrote:
Quote:
I think I may know why this is happening but I am a little fuzzy as to
what the solution should be as I am somewhat new to all of this.
>
Quote:
The bare-bones code that generates the error upon compilation is:
>
Quote:
class cart
{
* *public static string fetchCartCookieValue()
* *{
* * * * * *return Request.Cookies["cartCookie"].Value;
* *}
>
Quote:
}
>
Quote:
Any help is appreciated.
jake
>
Jake,
>
my guess would be you have not initialized Request and that Cookies is
not static.
If that is where the compile error is coming up that that would be your
problem.
Family Tree Mike
Guest
 
Posts: n/a
#4: Nov 21 '08

re: An object reference is required for the non-static field, method, orproperty 'System.Web.UI.Page.Request.get'


"jake" <jakedimano@gmail.comwrote in message
news:3f109280-3c59-4dcd-a597-2a62a6081fbb@f20g2000yqg.googlegroups.com...
Quote:
DH,
Yes I realize that that may well be true. But how may I code a static
method that can retrieve a cookie value?
jake
This code works for me, using VS 2008:

public class Cart
{
public static string fetchCartCookieValue()
{
return HttpContext.Current.Request.Cookies["cartCookie"].Value;
}
}





Closed Thread