Set HTML Content with ASP.NET Validation Controls

Generally when we use the Server side validation control in ASP.NET , used simple text to show the error notification message to the corresponding control.

But how to show the image content as the error message for the validation control instead of the simple plain text.

With the ASP.NET validation controls, we can set or used the images or HTML content to display the error notification when validation fails. We can also rendered the HTML format text or can embed the sounds to the validation controls.

To achieve this, here I will going to set Text Property with proper HTML content of an Validation control.

Here is code

<body>

    <form id="form1" runat="server">

    <div>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequriedField" runat="server" ValidationGroup="Must"

            ControlToValidate="TextBox1" ErrorMessage='<img src="error.png" style="height:28px;width:25px;vertical-align: top;"/><a href="#" title="Go to Help" style="text-decoration: blink;">Get Help </a>'></asp:RequiredFieldValidator>                

        </br>

        <asp:Button ID="button" runat="server" Text="submit" ValidationGroup="Must" />

    </div>

    </form>

</body>


Run it.

Now when you click on the submit button, It will display an image and link to show the error message for the control.

Output

Set-Html-to-validation-control-in-asp.net.png
  

Ebook Download
View all
Learn
View all