Use constructors to control how class members are populated. As written the Class2 member is initialized when Class1 is instantiated but not after the constructor executes. Therefore, the MyPage member of Class2 is null.
Public Class Class1
Dim MyPage As Page
Dim MyClass2 As Class2
Sub New(MePage As Page)
MyPage = MePage
MyClass2 = New Class2(MyPage)
End Sub
Sub Class1_Procedure()
MyPage.Response.Write("Class1 > Class1_Procedure</br>")
End Sub
Sub Class1_Procedure_Calling_Class2_Procedure()
MyPage.Response.Write("Class1 > Class1_Procedure_Calling_Class2_Procedure</br>")
MyClass2.Class2_Procedure()
End Sub
End Class
Public Class Class2
Dim MyPage As Page
Sub New(MePage As Page)
MyPage = MePage
End Sub
Sub Class2_Procedure()
MyPage.Response.Write("Class2 > Class2_Procedure</br>")
End Sub
End Class
This design creates dependencies which is an approach we try to avoid at all costs. Can you explain the use case?