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

J

jake

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
 
D

DH

jake said:
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.
 
J

jake

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


jake said:
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.
 
F

Family Tree Mike

jake said:
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;
}
}
 
J

jake

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;
  }
 }

Thank you Mike. That will fit my code very well..
jake
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top