从静态函数访问控制属性
这是我得到的:
<textarea id="TextArea1" rows="6" cols="20" runat="server"></textarea>
并在代码隐藏中:
partial class _Default : System.Web.UI.Page
{
[Webmethod()]
public static void Data(int TestNum)
{
if (TestNum > 0) TextArea1.InnerText = "hello world";
}
}
我收到以下错误:
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.
据我了解,我需要在共享函数中声明类的实例,如下所示:
_Default NewInstance = New _Default();
NewInstance.TextArea1.InnerText = "hello world";
我的问题是,有什么方法可以避免这样做吗?这是不好的做法,这样做会给我带来什么样的记忆或性能损失?
谢谢。
编辑:我应该提到静态声明是WebMethods所必需的
没有找到相关结果
已邀请:
4 个回复
亥套惟间连
揽芳僵迷仇
方法中删除
修饰符。
慰泥悍瓶
炉挤仙挟