title: Populate countries and cities dropdownlist with javascript in asp.net
body: <p>I have a register form in a fancybox as an inline content and can access to it in all the site as the link is in the master page.</p>
  
  <p>On the register form I have two dropdownlists one for country and the other for city. When the user changes the country the dropdownlist of cities refresh as the country selected previously. All the data from countries and cities i got it from a script <a href="https://bdhacker.wordpress.com/tag/all-countries-of-the-world/" rel="nofollow">https://bdhacker.wordpress.com/tag/all-countries-of-the-world/</a></p>
  
  <p>The problem is that when the user submits the form an error in firefox appears saying</p>
  
  <pre><code>Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration or &lt;%@ Page EnableEventValidation="true" %&gt; in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
  
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration or &lt;%@ Page EnableEventValidation="true" %&gt; in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
  </code></pre>
  
  <p>As the error point out i have to put enableeventvalidation=false. The problem is that i would have to do it on every page, as the fancybox is in the whole site, and i read it is not the best security practice. Other option would be to use, as the exception throws, to register every option with the clientscriptmanager of both dropdowns which would be tiresome because there are more than 200 countries and 10.000 cities!!!</p>
  
  <p>Any ideas what can i do??</p>
  
  <p>Here is some of the code</p>
  
  <pre><code>&lt;%@ Master Language="C#" AutoEventWireup="True" CodeBehind="Site.master.cs" Inherits="VozDirecta.SiteMaster" %&gt;
  &lt;script type="text/javascript" charset="utf-8"&gt;
      $(document).ready(function () {
          $("#RegistroLightbox").fancybox({
  
          });
      });
  
  &lt;/script&gt;
  
  &lt;body id="page1"&gt;
  &lt;form id="Form1" runat="server"&gt;
  &lt;asp:ScriptManager ID="ScriptManager" runat="server"&gt;
  &lt;/asp:ScriptManager&gt;
  &lt;a class="labelsTipolinks"  id="RegistroLightbox" href="#LightBoxRegistroDiv"&gt;Registro&lt;/a&gt;
  
   &lt;div style="display: none"&gt;
      &lt;div id="LightBoxRegistroDiv"&gt;
          &lt;asp:DropDownList ValidationGroup="grupoValidacionRegistroUsuario" runat="server"
                      ID="drpDownPais" CssClass="textoLightbox" AutoPostBack="false" CausesValidation="false"&gt;
                  &lt;/asp:DropDownList&gt;
           &lt;asp:DropDownList ValidationGroup="grupoValidacionRegistroUsuario" runat="server"
                      ID="drpDownCiudad" CssClass="textoLightbox" AutoPostBack="false" CausesValidation="false"&gt;
                  &lt;/asp:DropDownList&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I consider other option as to get the data from database and the bind to the dropdownlist but i'd rather stay with the javascript </p>