By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,326 Members | 2,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,326 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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.