Thursday, October 1, 2015

Applying Styles To Controls

So I have a custom control that inherits the BoundField class. Inside it, I added some validators. My problem was that I needed to apply styles to the TextBox in edit mode that should not be applied to the validators. The "ControlStyle" property that is already a part of the BoundField class applies to ALL the child controls rendered - so that won't work.

My solution was to create a "TextBoxStyle" property that gets applied (using ApplyStyle) once the TextBox is grabbed within the overridden InitializeDataCell method.

Here is the solution...

And here is a snippet of the implementation. Notice the "TextBoxStyle-CssClass" property...

No comments:

Post a Comment