在WebMethod中使用CreateControlCollection()

时间:2012-05-25 15:45:20

标签: vb.net webmethod controlcollection

我的代码调用WebMethod。在WebMethod中,我需要创建一个新的控件集合。在VB中我通常会写:

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

但是因为我在WebMethod中,我收到错误:

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.

有什么建议吗? 谢谢大家!

1 个答案:

答案 0 :(得分:0)

错误消息表示您正尝试从共享方法访问实例级成员或方法。如果要从共享方法访问实例级方法或成员,首先必须使用new运算符创建实例,并且可以从那里访问其公共成员和方法。