473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 4660
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alexander Tulai | last post by:
Hi, I've started using Java recently so the question may seem trivial. Is it possible to get rid of an object by simply creating a method (let's call it "die") in which one simply includes the...
3
by: Robert Hogan | last post by:
Hello, I am attempting to send emails using T-SQL (in a SQLServerAgent Job) using the stored procedure sp_SendSMTPMail. I created the stored proc using the following script that I got off a post...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
12
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline...
6
by: Matthias Kaeppler | last post by:
Hello, during a discussion on a C++ internet forum, some question came up regarding references and the lifetime of the objects they alias. I can't find any clear wording on that in the draft...
4
by: Jeff | last post by:
The derived class below passes a reference to an object in its own class to its base calss constructor. The code compiles and will run successfully as long as the base class constructor does not...
12
by: Belebele | last post by:
Suppose that a class A depends on class B because an object of class B is passed into A's constructor. See below: class B { ... }; class A { public: A(B const& b); ... };
5
by: removeps-generic | last post by:
Hi. I'm using placement new to re-initialize part of an object. Is this OK? struct BaseImp { All& r_all; BaseImp(All& all) : r_all(all) }; struct Calc::Imp : public BaseImp
21
by: Andrew Ward | last post by:
Consider the following: #include <iostream> struct X { int x; X() { x = 6; } };
10
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; class X { public: int value() const { return val; }
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.