asp.net - Accessing code behind functions from WebMethod -


i have code behind page has several method; 1 of them page method.

[webmethod] public static void resetdate(datetime thenewdate) {     loadcallhistory(thenewdate.date); }  protected void loadcallhistory(datetime thedate) { bunch of stuff } 

the method loadcallhistory works fine when page loads , can call other methods inside page. however, in web method part, gets underlined in red error "an object reference required non-static field".

how access functions page method part of code?

thanks.

you cannot call non-static method static context without having instance of class. either remove static resetdate or make loadcallhistory static.

however, if remove static resetdate must have instance of use method. approach create instance of class inside resetdate , use instance call loadcallhistory, this:

[webmethod] public static void resetdate(datetime thenewdate) {     var callhistoryhandler = new pages_callhistory();     callhistoryhandler.loadcallhistory(thenewdate.date); } 

the error message indicates resetdate has keyword static , loadcallhistory not. when using static either both of methods needs static or called method needs static, caller cannot static if called method not.

to quote msdn on "static classes , static class members"

a static class same non-static class, there 1 difference: static class cannot instantiated. in other words, cannot use new keyword create variable of class type. because there no instance variable, access members of static class using class name itself.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -