473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Nov 21 '08 #1
3 4693
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 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.
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...@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.
Nov 21 '08 #3
"jake" <ja********@gma il.comwrote in message
news:3f******** *************** ***********@f20 g2000yqg.google groups.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;
}
}

Nov 21 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5290
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 instruction: "this = null;" ? Would that work if the object has been previously placed in a list of similar objects? Do I need to go and delete it from the list or simply that list would now reference a "null" object? If so what would the size() of...
3
7059
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 here on google. CREATE PROCEDURE sp_SendSMTPMail (@From varchar(255), @To varchar(8000), @Subject varchar(255), @Body varchar(8000),
5
3742
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 their dtor is called immediately and not at the end of the function. to be able to use return objects (to avoid copying) i often assign them to a const reference. now, casting a const return object from a function to a non-const reference to this...
12
3278
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 MFVec operator+(const MFVec& z1, const MFVec& z2) // Global function { MFVec res = z1; res += z2 return res; // WHY???
6
1503
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 standard. Example 12.2 in the standard document illustrates that temporaries bound to references-to-const live as long as the reference does. But does it e.g. matter if the temporary was created in scope of a function body and has to outlive the...
4
5240
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 attempt to access the object -- since m_object is not actually created and initizialized until after the base constructor has been called. Any thoughts on the practice below? class Base { public:
12
2017
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
2923
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
1895
by: Andrew Ward | last post by:
Consider the following: #include <iostream> struct X { int x; X() { x = 6; } };
10
2600
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; class X { public: int value() const { return val; }
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.