Reputation: 17
I am currently using ASP.NET to validate my forms and instead of giving an error message if the fields are not valid I am using icons to show a green checkmark or a red exclamation mark.
<div class="name-field">
<asp:TextBox ID="RealName" Name="user-name" placeholder="请输入姓名" runat="server" CssClass="user-name" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RealName" CssClass="name-reset" ErrorMessage="<img src='image/mobile/exclamation-mark.png'>" />
</div>
Right now on field not valid, I am using 'ErrorMessage=...' to set the error icon. What is the best way I can also set the valid icon if the user has entered everything correctly?
Thanks.
Upvotes: 0
Views: 1354
Reputation: 415
Ok You can try this
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" ontextchanged="TextBox1_TextChanged">
your class code
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//eg: Label1.Text = Server.HtmlEncode(TextBox1.Text);
//you type your code here
}
Upvotes: 2
Reputation: 139
try to insert the image tag inside the RequiredFieldValidator tag like this:
<div class="name-field">
<asp:TextBox ID="RealName" Name="user-name" placeholder="请输入姓名" runat="server" CssClass="user-name" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RealName" CssClass="name-reset">
<img src="image/mobile/exclamation-mark.png" />
</asp:RequiredFieldValidator>
Upvotes: 0
Reputation: 415
you can try this
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Error" ControlToValidate="TextBox1"><img src="img src=image/mobile/exclamation-mark.png"/></asp:RequiredFieldValidator>
Upvotes: 1