I'm trying to change the color of a text in a label per condition.
I have tried the following option but none of them works:
if (gameNameTXT.Text != "")
{
pubName.ForeColor = System.Drawing.Color.Green;
pubName.ForeColor = System.Drawing.Color.FromArgb(11, 102, 35);
pubName.Attributes.CssStyle.Add("color", "green");
}
( pubName
in the ID of the label)
I have located the snipped code in the Page_Load
section and/or the Page_Init
section.
What I want is that the color of the text changes to green if the user wrote something in the text box.
do you try on onChange event of gameNameTXT?
may be you need set AutoPostBack=true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.