Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Custom Validator not working

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!
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

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.
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

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!
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?
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>
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

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!
ASKER CERTIFIED SOLUTION
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you sammySeltzer.