我希望我的构造函数WebControl
能够访问IsSpecial
(来自 HTML)的值。然而,它总是false
。我假设它false
在构造函数中,因为在构造函数方法结束之前它不会读取值。有没有办法让它知道IsSpecial
构造函数中的正确值?
C#:
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebControlExample runat=server></{0}:WebControlExample>")]
public class WebControlExample: WebControl, INamingContainer
{
private readonly int[] goodies;
public WebControlExample()
{
if (this.isSpecial)
{
goodies = new int[24];
}
else
{
//always reaches here
goodies = new int[48];
}
}
private bool isSpecial= false;
public bool IsSpecial
{
set
{
this.isSpecial= value;
}
}
}
HTML:
<xyz:WebControlExamplerunat="server" id="webControlExample" IsSpecial="true" />