469,602 Members | 1,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

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

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
Nov 21 '08 #1
3 4456
DH
jake wrote:
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.
Nov 21 '08 #2
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:
jake wrote:
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.
Nov 21 '08 #3
"jake" <ja********@gmail.comwrote in message
news:3f**********************************@f20g2000 yqg.googlegroups.com...
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;
}
}

Nov 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Alexander Tulai | last post: by
12 posts views Thread by Olumide | last post: by
6 posts views Thread by Matthias Kaeppler | last post: by
12 posts views Thread by Belebele | last post: by
5 posts views Thread by removeps-generic | last post: by
21 posts views Thread by Andrew Ward | last post: by
10 posts views Thread by subramanian100in | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.