Search This Blog

Saturday, August 18, 2012

Showing image when validation fails using validation control



One thing to note here is that you have to set the “Display” property of the validation control to “Dynamic”.  If you set the “Display” property to “None”, which we

usually use with validation summary control, then the image will not be displayed. So its very important to set the “Display” property to “Dynamic'” for this to work.
When text box not blank no validation show.

When text box value blank then show RequiredFieldValidator in form of image.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="SBIWEB.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Submit" />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="TextBox1" ErrorMessage="Required." Display="Dynamic"><img src=images/cute_ball_stop.png /></asp:RequiredFieldValidator>
 
    </div>
    </form>
</body>
</html>

No comments :