The scenario applies to simple Label or Literals in ASP.NET. I am currently using a DynamicControl with the Mode set to ReadOnly. This causes the generation of a Literal and thus looks like plain text in the browser. This is great in most cases.
However, sometimes I want the text to have a border around it and maybe a different background to make it look like a read only TextBox.
Thankfully there is an easy solution. Using CSS we can define a style
border: solid 1px #bcbcbc;
We could include background color if we wanted to change that also.
To use the style, we can put a span tag around whatever we want the border around and setting the class=”DDTextWithBorder” attribute.
An example of that is:
<span class="DDTextWithBorder"><asp:DynamicControl ID="TotalPointsDynamicControl" runat="server" DataField="TotalPoints" Mode="ReadOnly"/></span>
Another way is to just set the CssClass property of the control we want to put a border around.
<asp:DynamicControl ID="TotalPointsDynamicControl" runat="server" DataField="TotalPoints" Mode="ReadOnly" CssClass="DDTextWithBorder"/>
That’s it. Quite simple, but powerful.