简体   繁体   中英

ASP.NET RequiredFieldValidator “Message” on Valid

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.

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 
}

你可以试试这个

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Error" ControlToValidate="TextBox1"><img src="img src=image/mobile/exclamation-mark.png"/></asp:RequiredFieldValidator> 

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM