ASP.NET : How to use image in error message in validation Control

If you are generating error  message to the client side then you can use any type of validation in given ToolBox such as RequiredField validator , compare validator , custom validator etc. If you want to use Image for easy understand then you should insert image in Text property of the validation control.

 <asp:RequiredFieldValidator  ControlToValidate ="TextBox1" Text="<img width='40px' height='40px' src='error.jpg' />" ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>


Here we have used HTML Image Tag inside Text property of control.
Example
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:TextBox ID="TextBox1" runat="server" Width="201px"></asp:TextBox>
        <asp:RequiredFieldValidator  ControlToValidate ="TextBox1" Text="<img width='40px' height='40px' src='error.jpg' />" ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>

        <asp:Button ID="Button1" runat="server" Text="Check RequiredField" />
    </div>
    </form>
</body>
</html>


Output
ASP.NET : How to use image in error message in validation Control

ASP.NET : How to use image in error message in validation Control ASP.NET : How to use image in error message in validation Control Reviewed by Jacob Lefore on December 29, 2015 Rating: 5

No comments