473,387 Members | 1,574 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,387 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 4659
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.