Click here to Skip to main content
15,178,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following is my Input string in
ABCDEFGHIJKL. i want to highlight wrong input from string

suppose user enter wrong input "A" in ABCDEFGHIJKL in that case i wnt to set color to that particular text.
Updated 8-Jun-15 22:52pm
CHill60 9-Jun-15 4:14am
What have you tried?
Shivaram_i 9-Jun-15 4:51am
How we check that is wrong input or not??? User can enter any input right???Will you please make it more clear?

1 solution

Use a asp:Literal control and set to pass through mode.
Then in code construct the markup for the text you want to highlight using style tags:

<asp:literal runat="server" id="literal1" mode="Passthrough" xmlns:asp="#unknown" />

private void YourInputMethod(string inputText)
    // Add your logic to validate correct or incorrect value
    // bool valid = Validate(...);
    // ...
    // string invalidValue = "" <-- set the invalid value
    // Replace the invalid text in the input with a placeholder:
    // inputText.Replace(invalidValue,"[invalid]");

    if (!valid)
        string invalidStyle = Highlighter(invalidValue, "InvalidInputCSSStyle")
    Literal1.Text = inputText;

private string Highlighter(string valueToStyle, string styleName)
    return "<label style="" + styleName + "">" + valueToStyle + "</label>";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900