My brain is not working this morning. I need some help accessing some members from a static method. Here is a sample code, how can I modify this so that TestMethod() has access to testInt
public class TestPage
{
protected int testInt { get; set; }
protected void BuildSomething
{
// Can access here
}
[ScriptMethod, WebMethod]
public static void TestMethod()
{
// I am accessing this method from a PageMethod call on the clientside
// No access here
}
}
testIntis declared as an instance field. It is impossible for astaticmethod to access an instance field without having a reference to an instance of the defining class. Thus, either declaretestIntas static, or changeTestMethodto accept an instance ofTestPage. Sois okay as is
Which of these is right depends very much on what you’re trying to model. If
testIntrepresents state of an instance ofTestPagethen use the latter. IftestIntis something about the typeTestPagethen use the former.