Click here to Skip to main content
15,446,510 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass a variable value into a static WebMethod, but failed with the error: "
VB
Error   37  An object reference is required for the non-static field, method, or property 

What approach should be used to solve this problem? Thanks in advance.
Posted
Comments
Karthik_Mahalingam 10-Jan-14 11:40am    
post your code..
[no name] 10-Jan-14 11:44am     CRLF
Simplified code is below. Thanks. string s = "sss"; [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)] public static string[][] GetData2(string route, string mA, string mB) { string routeInput = s; ... }
Ron Beyer 10-Jan-14 11:46am    
string s needs to be static too.

1 solution

C#
string s = "sss";
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
        public static string[][] GetData2(string route, string mA, string mB)  {
            string routeInput = s; 
        ... }


s needs to be a static reference, change to:

C#
static string s = "sss";

...
 
Share this answer
 
Comments
[no name] 10-Jan-14 13:01pm    
Ron: Thanks for your response. Your approach works for an assigned value. In my scenario, the variable's value is dynamically (e.g. value in a TextBox). Do you have any idea to pass the value? Thanks again.
Ron Beyer 10-Jan-14 15:08pm    
Why not make it a parameter of the GetData2 method then?
[no name] 10-Jan-14 15:15pm    
I did tried in multiple ways including you mentioned w/ parameters (see my post at http://www.codeproject.com/Questions/709250/JavaScript-Internal-Server-Error). If that one works, I will not need to this one. Hopefully you can hint me how to debug that one. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900