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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jake

    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 fetchCartCookie Value()
    {
    return Request.Cookies["cartCookie "].Value;
    }


    }

    Any help is appreciated.
    jake
  • DH

    #2
    Re: An object reference is required for the non-static field, method,or property 'System.Web.UI. Page.Request.ge t'

    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 fetchCartCookie Value()
    {
    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.

    Comment

    • jake

      #3
      Re: An object reference is required for the non-static field, method,or property 'System.Web.UI. Page.Request.ge t'

      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...@mo re.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 fetchCartCookie Value()
         {
                 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.

      Comment

      • Family Tree Mike

        #4
        Re: An object reference is required for the non-static field, method, or property 'System.Web.UI. Page.Request.ge t'

        "jake" <jakedimano@gma il.comwrote in message
        news:3f109280-3c59-4dcd-a597-2a62a6081fbb@f2 0g2000yqg.googl egroups.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 fetchCartCookie Value()
        {
        return HttpContext.Cur rent.Request.Co okies["cartCookie "].Value;
        }
        }





        Comment

        Working...