How can I make a validation icon next to asp: textbox?

Using this code, I can get a very crappy red letter with an inscription.

<form id="frmValidator" action="required.aspx" method="post" runat="server"> Enter Your Name: <asp:TextBox id="txtName" runat="server" /> <asp:RequiredFieldValidator id="valTxtName" ControlToValidate="txtName" ErrorMessage="Please enter your name!" runat="server" /> <br /> <asp:button id="btnSubmit" text="Submit" runat="server" /> </form> 

Is there some way for me to have a green icon (I have this image, so I think I just need to edit it) the view disappears next to the control?

Thanks a bunch. :)

+4
source share
2 answers

You can do it

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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></title> <style type="text/css"> </style> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" BorderStyle="None" ControlToValidate="TextBox1" CssClass="newStyle1"></asp:RequiredFieldValidator> </div> <asp:Button ID="Button1" runat="server" Text="Button" /> </form> </body> </html> .newStyle1 { background-image: url('Pic.png'); width: 500px; height: 300px; } 

Thus, in principle, there simply is no text for the error message and set the css property in the validation elements to have a css class.

+1
source

You set the ErrorMessage property with an image link

eg. ErrorMessage='<img src="error.gif">'

See this MSDN article.

+4
source

Source: https://habr.com/ru/post/1299175/


All Articles