Show images in error messages using asp .net

 In this article we will see how to show custom images in validation controls using asp .Net.

Step1: Copy image to website folder which you want to show in error messages. For more information you can visit my thread http://www.codingfusion.com/Post/Create-a-asp--net-webforms-website--Copy-image-to

Step2: Create three textboxes and apply necessary validations. 

 

Step3: Paste image tag insite ErrorMessage property. ErrorMessage="<img src='arrow.png' />"

<table>
      <tbody><tr>
          <td>
              <b>Name</b>
          </td>
          <td>
              <asp:textbox runat="server" id="txtName">
              <asp:requiredfieldvalidator id="RequiredFieldValidator1" errormessage="<img src='arrow.png' />
                  Please enter your name." controltovalidate="txtName" runat="server">
          </asp:requiredfieldvalidator></asp:textbox></td>
      </tr>
      <tr>
          <td>
              <b>Age</b>
          </td>
          <td>
              <asp:textbox runat="server" id="txtAge">
              <asp:requiredfieldvalidator id="RequiredFieldValidator2" errormessage="<img src='arrow.png' /> Please enter your age." controltovalidate="txtAge" runat="server">
              <asp:comparevalidator id="CompareValidator1" errormessage="Age must be integer." type="Integer" operator="DataTypeCheck" controltovalidate="txtAge" runat="server">
          </asp:comparevalidator></asp:requiredfieldvalidator></asp:textbox></td>
      </tr>
      <tr>
          <td>
              <b>Email</b>
          </td>
          <td>
              <asp:textbox runat="server" id="txtEmail">
              <asp:requiredfieldvalidator id="RequiredFieldValidator3" errormessage="<img src='arrow.png' /> Please enter your email." controltovalidate="txtEmail" runat="server">
              <asp:regularexpressionvalidator id="RegularExpressionValidator1" errormessage="<img src='arrow.png' /> Invalid email format." controltovalidate="txtEmail" runat="server" validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
          </asp:regularexpressionvalidator></asp:requiredfieldvalidator></asp:textbox></td>
      </tr>
      <tr>
          <td>
                
          </td>
          <td>
              <asp:button text="Save" id="btnSave" runat="server">
          </asp:button></td>
      </tr>
  </tbody></table>

Final Output: 

 Show-Images-In-error-messages-in-asp-net-codingfusion

 

 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2025 CodingFusion
50+ C# Programs for beginners to practice