关于自定义控件弹出“未能完成操作。无效的FORMATETC结构”。
重做放牛娃 2010-04-30 11:06:54 刚开始学习自定义控件,把MSDN中的代码粘贴了下来,生成了一个类,代码如下:
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ControlLibrary
{
class WelcomeLabel : CompositeControl
{
public virtual string Text
{
get
{
string s = (string)ViewState["Text"];
return (s == null) ? string.Empty : s;
}
set
{
ViewState["Text"] = value;
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
writer.WriteEncodedText(Text);
if (Context != null)
{
string s = Context.User.Identity.Name;
if (s != null && s != string.Empty)
{
string[] split = s.Split('\\');
int n = split.Length - 1;
if (split[n] != string.Empty)
{
writer.Write(", ");
writer.Write(split[n]);
}
}
}
writer.Write("!");
}
}
}
可当我要把这个控件从工具箱拖到测试界面时出现了“未能完成操作。无效的FORMATETC结构”的错误,不知是何原因??