非静态的字段、方法或属性“System.Web.UI.WebControls.Label.Text.get”要求对象引用
运行提示为
非静态的字段、方法或属性“System.Web.UI.WebControls.Label.Text.get”要求对象引用
代码如下:
- C# code
using System;using System.Runtime.InteropServices;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Serialization;using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using Microsoft.SharePoint.WebPartPages;using ActiveDs;using Velde;namespace WebPart1{ [Guid("0fcf1f6b-e232-4911-ae56-27158078c75d")] public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart { public WebPart1() { } protected override void CreateChildControls() { base.CreateChildControls(); // TODO: add custom rendering code here. AD ad = new AD(); bool t5 = ad.createUserAccount("OU=te33fd,DC=BOM,DC=com", "wskty", "wskandwsk", "临", "时的", "2010-12-12"); Label label = new Label(); if (t5 == true) Label.Text = "帐号为创建成功!"; else Label.Text = "对不起,帐号未创建!"; //label.Text = "Hello World"; this.Controls.Add(label); } }}
请高手解决下
[解决办法]
写错了吧,把类和对象名搞混了,红色部分应该是label
Label label = new Label();
if (t5 == true)
Label.Text = "帐号为创建成功!";
else
Label.Text = "对不起,帐号未创建!";
[解决办法]
Label label1= new Label();
if (t5 == true)
label1.Text = "帐号为创建成功!";
else
label1.Text = "对不起,帐号未创建!";
取名字也取的清楚点的啊!现在弄的大小写都分不清楚