2

I have following validator control. How can we set the color of Text of this control from code behind?

Note: Text of the control is * as shown in the code below.

CODE

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
    Text="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />

4

2 回答 2

2

使用ForeColor属性:

 RequiredFieldValidator1.ForeColor = System.Drawing.Color.Red;
于 2012-12-19T17:29:48.520 回答
1

像这样的东西应该工作:

Style myStyle = new Style();
s.BackColor = System.Drawing.Color.Red;

valEmailRecipients.Style = myStyle;

或者简单地说:

valEmailRecipients.Style.ForeColor= System.Drawing.Color.Red;

请参阅此处以供参考,也请参阅此处

于 2012-12-19T17:05:08.213 回答