Using CreateControlCollection() from within a WebMethod

139 Views Asked by At

my code calls a WebMethod. Within that WebMethod I have the need to create a new control collection. In VB I would normally write:

Dim cc As System.Web.UI.ControlCollection = CreateControlCollection()

But because I'm inside a WebMethod, I get the error :

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Any suggestions please ? Thanks folks !

1

There are 1 best solutions below

1
On

The error message implies you are trying to access an instance-level member or method from a shared method. If you want to access an instance-level method or member from a shared method, first you must create an instance using the new operator and you can access its public members and methods from there on.