ASP.NET - Asp.net Validations Problem ? - Asked By aileni giri on 12-Nov-12 02:06 AM

i have  a page on that i have one  textbox and fileupload control and i applied validation controls on it.
i have written the javascript code  to when the button submit ,the textbox border color changed to Red color ,if there is no
valid data. .

my problem is  when i enter the data into textbox still the textbox  color is in red color,..i Applied RequiredField Validator control.

here is  my code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head" runat="server">
    <title></title>

    <style type="text/css">
      body
      {
        font-family: Verdana;
        font-size: 12pt;
      }
      .ErrorCtrl
      {
      
        border: solid 2px Red;
      }
    </style>
  
</head>
<body>
    <form id="FormControl" runat="server">
    <div>
      <asp:FileUpload ID="fu1" runat="server" />
      <asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="fu1" ErrorMessage="must have to upload">
      </asp:RequiredFieldValidator>
      <br /><br />
      UserName:
      <asp:TextBox ID="txtUname" onblur="return claerAll();" runat="server"></asp:TextBox>
      <asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="txtUname" ErrorMessage="Shouldn't Blank">
      </asp:RequiredFieldValidator>
      <br /><br />
      <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
    </div>
</form>

<script type="text/javascript">
    function WebForm_OnSubmit()
    {
      if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false)
      {
        for (var i in Page_Validators)
        {
          try
          {
            var control = document.getElementById(Page_Validators[i].controltovalidate);
            if (!Page_Validators[i].isvalid)
            {
              control.className = "ErrorCtrl";
            }
            else
            {
              control.className = "ErrorCtrl1";
            }
          }

          catch (e) { }
        }
        return false;
      }
      return true;
    }
</script>
</body>
</html>
Chiranjeevi S replied to aileni giri on 21-Nov-12 01:39 AM
Hi.
I have checked your code and it is working fine.
You have to click the button after entering text into textbox.
aileni giri replied to Chiranjeevi S on 23-Nov-12 03:45 AM
what  i need is  when i leaving textbox  ,the red color border should be go,with out clikcing on submit button.