Cannot set CssClass property in inherited Label / TextBox WebControl
I have created a very simple custom control:
[assembly: System.Web.UI.TagPrefix("CustomMultiLineTextBox", "evo")]
public class CustomMultiLineTextBox :
System.Web.UI.WebControls.TextBox
{
public override int Rows
{
get
{
return 5;
}
}
public override System.Web.UI.WebControls.TextBoxMode TextMode
{
get
{
return System.Web.UI.WebControls.TextBoxMode.MultiLine;
}
}
public override string CssClass
{
get
{
return "textboxStyle";
}
set
{
//base.CssClass = "textboxStyle";
开发者_开发问答 base.CssClass = value;
}
}
}
}
However, when I drop this control onto my aspx page the CssClass does not seem to be applied. The TextMode and Rows property are set correctly.
<evo:CustomMultiLineTextBox ID="txtTrainingNeeds" runat="server">
</evo:CustomMultiLineTextBox>
Only if I add CssClass="textboxStyle" to markup will the CssClass be applied.
Any suggestions?
Thanks in advance
Since it doesn't look like you're modifying behavior, only data, I would set the properties to the values you want in the constructor instead of overriding the properties themselves.
public CustomMultiLineTextBox()
{
Rows = 5;
TextBoxMode = System.Web.UI.WebControls.TextBoxMode.MultiLine;
CssClass = "textboxStyle";
}
精彩评论