locked
Validation control's ErrorMessage RRS feed

  • Question

  • User1453549677 posted

    Is there a way to access the value of a validation control's ErrorMessage property?

    Thursday, May 12, 2016 3:51 PM

Answers

  • User61956409 posted

    Hi drl,

    Is there a way to access the value of a validation control's ErrorMessage property?

    Firstly, it is easy for us to get/set ErrorMessage property from code behind.

    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="required"></asp:RequiredFieldValidator>
    </div>
    
    RequiredFieldValidator1.ErrorMessage = "It is required!";

    Secondly, the ErrorMessage property value will be displayed as innerHTML, you could access it by using JavaScript.

    document.getElementById("RequiredFieldValidator1").innerHTML
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 13, 2016 3:29 AM