Murali Kris

Murali Kris

  • 1.5k
  • 254
  • 48k

TextBox validation with CustomValidator Error Msg

Aug 1 2019 4:45 AM
Hi all,
 
i am sure its very small but i tried a lot since not a expert in c# validations
kindly help me here for validation.
1. I have two textboxs one for username, another for just email
2. i have to use CustomValidator for textbox.
 
the movment when cursour goes to next text box with blank(if textbox1 isempty)from first, then i want to display customvalidator error message.
 
Yes we have RequiredFiled validator option, it shows the msg when press the submit buttion only but not when cursor moves to next textbox.
 
how to display errormsg when cursor moves to next textbox like txtbox1 should not empty.
 
 from UI.ASPX Source
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage=""
Display="Dynamic"
forecolor="Red"
OnServerValidate="CustomValidator1_ServerValidate"
ControlToValidate="TxtUserName"
ValidateEmptyText="True"></asp:CustomValidator>
 
 From UI.ASPX.cs code
 
protected void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
   if (args.Value == "")
   {
   CustomValidator1.ErrorMessage = "error from custom";
   args.IsValid = false;
   }
}
 
 
Kindly help me with code for the above requirement.
 
 

Answers (2)