Reputation: 2566
I am having difficulties in adding Style property to a UserControl. There is a parser exception when I try to view the consumer page.
private Style _headerStyle = new Style();
public Style HeaderStyle
{
get { return _headerStyle ; }
set
{
_headerStyle .CopyFrom(value);
}
}
Usage:
Style="border: 1px solid blue;"
Error:
Cannot create an object of type 'System.Web.UI.WebControls.Style' from its string representation ...
Upvotes: 1
Views: 942
Reputation: 460038
A Style
instance is not a string and vice-versa. Style.CopyFrom
expects a Style
as argument and you're passing a String
. That's the reason why it cannot be copied to the new style object.
If you want to give your UserControl a border programmatically:
myControl.HeaderStyle.BorderStyle = BorderStyle.Solid;
myControl.HeaderStyle.BorderWidth = new Unit(1);
myControl.HeaderStyle.BorderColor = System.Drawing.Color.Blue;
Upvotes: 1