We help IT Professionals succeed at work.

Custom  Validator not working

514 Views
Last Modified: 2015-09-25
Hello Experts,
My CustomValidator is not working in my local machine.  But when deployed in Windows Server 2008 machine, it is working.  Any idea why it is behaving like this?  Below is the environment I am using.  Thank you in advance.

OS: Windows 7
Visual Studio: 2010
Server: Windows 2008 R2

Thank You!
Comment
Watch Question

Top Expert 2011

Commented:
Since no code, I fashion a guess.

What browser are you using?

I suspect you are using jquery?

What if you add this line to the top of your page between <head>...</head> section?

<meta http-equiv="X-UA-Compatible" content="IE=7, IE=8, IE=9, IE=10, IE=11" />

Open in new window


You can also hit the f12 key if using IE or firebug if using firefox to get better idea of what is going on.

If all else fails, you can show some code.

Author

Commented:
Hi sammySeltzer,
Thank you for your help.  I am using IE 11.  I am not using jQuery.  Just using ASP.NET inbuilt validator with JavaScript.    Please explain more, how the F12 key works?  Also, what does the following line will do?

<meta http-equiv="X-UA-Compatible" content="IE=7, IE=8, IE=9, IE=10, IE=11" />

Thank you!
Top Expert 2011

Commented:
I suggested using F12 because I assumed you were using some javascript. That helps with debugging.

The meta tag is intended to make those browsers listed compatible, again, assume some jquery is being used.

can you show your code, just the customValidator bit?

Author

Commented:
If I copy this code to a different program and try to run, it works just fine.  

<HTML>
      <HEAD>
            <title>Credit Card Check</title>
            <script language="javascript">
            function ValidateMonth(source, arguments)
            {
                  if(window.Form1.ddlMonth.options.selectedIndex == 0)
                        arguments.IsValid = false;
                  else
                        arguments.IsValid = true;
                        
            }

            </script>
       </HEAD>


      <body bgColor="#a7a7db" MS_POSITIONING="GridLayout">
            <form id="Form1" onsubmit="javascript:ValidateMe();" method="post" runat="server">
                  <table style="WIDTH: 592px" cellSpacing="0" cellPadding="0" border="0">

                        <tr>
                              <td style="WIDTH: 305px; HEIGHT: 5px">Expiration Month:</td>
                              <td class="style3"><asp:dropdownlist id="ddlMonth" runat="server" Width="112px">
                                          <asp:ListItem Value="Select Month">Select Month</asp:ListItem>
                                          <asp:ListItem Value="01">Jan</asp:ListItem>
                                          <asp:ListItem Value="02">Feb</asp:ListItem>
                                          <asp:ListItem Value="03">Mar</asp:ListItem>
                                          <asp:ListItem Value="04">Apr</asp:ListItem>
                                          <asp:ListItem Value="05">May</asp:ListItem>
                                          <asp:ListItem Value="06">Jun</asp:ListItem>
                                          <asp:ListItem Value="07">Jul</asp:ListItem>
                                          <asp:ListItem Value="08">Aug</asp:ListItem>
                                          <asp:ListItem Value="09">Sep</asp:ListItem>
                                          <asp:ListItem Value="10">Oct</asp:ListItem>
                                          <asp:ListItem Value="11">Nov</asp:ListItem>
                                          <asp:ListItem Value="12">Dec</asp:ListItem>
                                    </asp:dropdownlist>&nbsp;&nbsp;
                        </tr>
                        <tr>
                              <td style="HEIGHT: 18px" colSpan="3"><asp:customvalidator id="Customvalidator3" runat="server" ControlToValidate="ddlMonth" ErrorMessage="Selected Month is not a valid selection "
                        ClientValidationFunction="ValidateMonth"></asp:customvalidator><br />

                        </tr>

            </form>
      </body>
</HTML>
Top Expert 2011

Commented:
Sorry for the late response.

If all you are doing is just validating the dropdownlist, why not make it simple and easy?

Something like:

       <HEAD>
             <title>Credit Card Check</title>
        </HEAD>


       <body bgColor="#a7a7db" MS_POSITIONING="GridLayout">
             <form id="Form1" onsubmit="javascript:ValidateMe();" method="post" runat="server">
                   <table style="WIDTH: 592px" cellSpacing="0" cellPadding="0" border="0">

                         <tr>
                               <td style="WIDTH: 305px; HEIGHT: 5px">Expiration Month:</td>
                               <td class="style3"><asp:dropdownlist id="ddlMonth" runat="server" Width="112px" AppendDataBoundItems="True">
                                           <asp:ListItem Value="Select Month">Select Month</asp:ListItem>
                                           <asp:ListItem Value="01">Jan</asp:ListItem>
                                           <asp:ListItem Value="02">Feb</asp:ListItem>
                                           <asp:ListItem Value="03">Mar</asp:ListItem>
                                           <asp:ListItem Value="04">Apr</asp:ListItem>
                                           <asp:ListItem Value="05">May</asp:ListItem>
                                           <asp:ListItem Value="06">Jun</asp:ListItem>
                                           <asp:ListItem Value="07">Jul</asp:ListItem>
                                           <asp:ListItem Value="08">Aug</asp:ListItem>
                                           <asp:ListItem Value="09">Sep</asp:ListItem>
                                           <asp:ListItem Value="10">Oct</asp:ListItem>
                                           <asp:ListItem Value="11">Nov</asp:ListItem>
                                           <asp:ListItem Value="12">Dec</asp:ListItem>
                                     </asp:dropdownlist>&nbsp;&nbsp;
                                     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlMonth"
				     ErrorMessage="Selected Month is not a valid selection" InitialValue="Select Month"></asp:RequiredFieldValidator>
                           </td>
                                
                         </tr>

             </form>
       </body>
 </HTML> 

Open in new window

Author

Commented:
Thank you sammySeltzer,

The reason I am not using that is, I have Year to select from the dropdown too and  I need to use the CustomValidator to validate Year must be >= Current Year, which RequiredFieldValidator cannot validate this.

The problem is this is not a new code.  This has been running for years together.  I don't know what happened, this stopped working.  

Thank you!
Top Expert 2011
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you sammySeltzer.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.