On Nov 21, 4:10*pm, DH <I.dont.n...@more.spamwrote:
Quote:
jake wrote:
Quote:
If I may add that the error does not occur and it executes properly
when I make the getCartCookie() an instance method rather than a
static method.
>
Quote:
The error is the one mention in the title of this message.
Thanks,
jake
>
Quote:
On Nov 21, 3:44 pm, DH <I.dont.n...@more.spamwrote:
Quote:
jake wrote:
>I think I may 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.
>My simplified code that generates the error is:
>public static string getCartCookieValue()
>{
>* *if (Request.Cookies["tepcart"] != null)
>* *{
>* * * * * *using (CartServiceClient client = new CartServiceClient())
>* * * * * *{
>* * * * * * * * * *retval = client.getCartId(Request.Cookies["tepcart"].Value);
>* * * * * * * * * *client.Close();
>* * * * * *}
>* *}
>* *return retval;
>}
where are you declaring retval? if you are declaring it inside of the
using statement it is becuase the scope of it is just inside of the
using statment.
what is the exact error you are getting?
>
Are you using a .Net class or your own class? Either way there is a
difference between static and non-static methods.
Google "C# static vs Non static" and there are tons of articles if you
are not familiar with it.
The reason you get that error when you dont make getCartCookie() an
instance is becuase the methods are not static which means they are
instance methods. If it is your class that you are using you might be
able to get away with making them static but you need to look at the
overall picture and see if it is a good idea or not. I dont recommend
doing that if other project and classes use it unless you really have to.
It is a .Net class. A simple web page actually. I was only slightly
fuzzy on the concept and I did a little quick reading after your last
message and I think I understand it much better now. The
"Request.get" method is a non-static method that can only be in other
non-static methods. I guess the question now is: Is there another way
to get the cookies other than via the Request object?