title: code behind field validation only if value is selected in dropdown list
body: <p>I'm not an asp.net guru, so I'm facing bad times with this silly matter.
  I have a registration form where a field (VAT NUMBER called 'piva') must be validate only if from a dropdown list the value "IT" has been selected.</p>
  
  <p>This is the front code:</p>
  
  <pre><code>&lt;asp:TextBox ID="pivaTextBox" runat="server" Text='&lt;%# Bind("piva") %&gt;' 
  MaxLength="50" Width="400px" /&gt;
  
  &lt;asp:RequiredFieldValidator ID="RequiredPiva" runat="server" 
  ControlToValidate="pivaTextBox" 
  ErrorMessage="&lt;%$ Resources:Resource, CampoObbligatorio %&gt;" Display="Dynamic" 
  CssClass="little_text" /&gt;
  
  &lt;asp:CustomValidator ID="PivaEsistente" runat="server" 
  ErrorMessage="Partita IVA esistente nel database" meta:resourcekey="PivaEsistente" 
  ControlToValidate="pivaTextBox" CssClass="little_text" Display="Dynamic" 
  onservervalidate="PIVAEsistente_ServerValidate"&gt;&lt;/asp:CustomValidator&gt;
  
  &lt;asp:RegularExpressionValidator ID="PivaSize" runat="server" ControlToValidate="pivaTextBox" CssClass="little_text" Display="Dynamic" ErrorMessage="Check the VAT Number length. 11 characters and only numbers."  ValidationExpression="[0-9]{11}"  ValidationGroup="pivaItalia"&gt;
  &lt;/asp:RegularExpressionValidator&gt;
  </code></pre>
  
  <p>In the code behind I wrote this:</p>
  
  <pre><code>protected void PIVAEsistente_ServerValidate(object source, ServerValidateEventArgs args)
  {
      string piva = args.Value;
      using (CMALinqModelDataContext ent = new CMALinqModelDataContext())
      {
          var n = (from u in ent.VUser
                   where u.piva == piva
                   select u).Count&lt;VUser&gt;();
          args.IsValid = n.ToString().Equals("0");
      }
  }
  
  protected void nazioneDropDownList_SelectedIndexChanged(object sender, EventArgs e)
  {
      DropDownList ddl = (DropDownList)sender;
      DropDownList ddlProv = (DropDownList)FormUser.FindControl("provinciaDropDownList");
  
  
      if ("it".Equals(ddl.SelectedValue))
      {
          ddlProv.Enabled = true;
          Page.Validate("pivaItalia");
  
      }
      else
      {
          ddlProv.SelectedIndex = 0;
          ddlProv.Enabled = false;
      }
  
  }
  </code></pre>
  
  <p>the first method checks if a VAT number already exists and it works.
  The second one check if "it" has been selected from the nations dropdown list and unlock the provinces dropdownlist AND SHOULD validate the VAT number according the RegularExpressionValidator above.</p>
  
  <p>The fact is that it is always validate, but worst even if I get the error message, the form can be submitted.
  That's not good.</p>
  
  <p>Anyone could suggest any solution? What am I missing?</p>