首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

GetContext method Cannot be null解决方法!

2014-01-28 
做一个asp.net自定义控件。 protected override void RenderContents(HtmlTextWriter output) { // CreateHt

做一个asp.net自定义控件。
protected override void RenderContents(HtmlTextWriter output)
{
// CreateHtml();
if (Text == null)
{
output.Write( "配置控件参数 ");
}
else
{
output.Write(Text);
}
}
CreateHtml()创建的页面的html内容,是在系统运行时才能生成呢。因为我要在web容器中取一些值。
这样在把这个控件放到一个aspx页面时,在设计的时候总是显示出错。GetContext method Cannot be null
请问如果才能让它在设计的时候不出错呀。就像GridView,在设计时显示数据的样式。但里面的实际数据是在运行的时候才显示的。

这是我初次编写自定义控件。请大家帮帮忙。

------解决方法--------------------------------------------------------
要多写一个类的,继承自ControlDesigner

比如你写了一个CCC类,那么就这样:

[//其它的Attributes, Designer(typeof(CCCDesigner))]
public class CCC : WebControl, INamingContainer
{
//你的代码
}

public class CCCDesigner : ControlDesigner
{
//你的代码,重写GetDesignTimeHtml和GetErrorDesignTimeHtml就OK了
}
------解决方法--------------------------------------------------------
protected override void RenderContents(HtmlTextWriter output)
{
if(this.DesignMode
CreateHtml();
if (Text == null)
{
output.Write( "配置控件参数 ");
}
else
{
output.Write(Text);
}
}

没看懂你'if (Text == null)'是什么意思。
------解决方法--------------------------------------------------------
少了一个'!'。

protected override void RenderContents(HtmlTextWriter output)
{
if(!this.DesignMode)
CreateHtml();
if (Text == null)         

热点排行