2012-08-10 92 views
0

我在fancybox中有一个注册表单作为内联内容,并且可以在所有站点中访问它,因为链接位于母版页中。在asp.net中填充国家和城市的javascript下载列表

在注册表格中,我有两个下拉列表分别用于国家和城市。当用户更改国家时,城市的下拉列表会根据之前选择的国家进行更新。所有的国家和城市的数据我是从一个脚本https://bdhacker.wordpress.com/tag/all-countries-of-the-world/

的问题是,当用户提交表单Firefox中的错误出现说

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> 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 <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> 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. 

由于错误指出我已经把enableeventvalidation =假。问题是,我必须在每个页面上都做这件事,因为fancybox在整个网站中,我读到它并不是最好的安全措施。其他选择将使用,作为例外抛出,注册与这两个下拉的clientscriptmanager每个选项,这将是令人厌烦的,因为有超过200个国家和10,000个城市!

任何想法我能做些什么?

下面是一些代码

<%@ Master Language="C#" AutoEventWireup="True" CodeBehind="Site.master.cs" Inherits="VozDirecta.SiteMaster" %> 
<script type="text/javascript" charset="utf-8"> 
    $(document).ready(function() { 
     $("#RegistroLightbox").fancybox({ 

     }); 
    }); 

</script> 

<body id="page1"> 
<form id="Form1" runat="server"> 
<asp:ScriptManager ID="ScriptManager" runat="server"> 
</asp:ScriptManager> 
<a class="labelsTipolinks" id="RegistroLightbox" href="#LightBoxRegistroDiv">Registro</a> 

<div style="display: none"> 
    <div id="LightBoxRegistroDiv"> 
     <asp:DropDownList ValidationGroup="grupoValidacionRegistroUsuario" runat="server" 
        ID="drpDownPais" CssClass="textoLightbox" AutoPostBack="false" CausesValidation="false"> 
       </asp:DropDownList> 
     <asp:DropDownList ValidationGroup="grupoValidacionRegistroUsuario" runat="server" 
        ID="drpDownCiudad" CssClass="textoLightbox" AutoPostBack="false" CausesValidation="false"> 
       </asp:DropDownList> 
    </div> 
</div> 

我考虑其他选项以获得从数据库中的数据,并绑定到下拉列表,但我宁愿留在JavaScript的

回答

0

我结束了使用纯html选择控件并将两个值都保存在两个hiddenField中。有了这个,我可以保持与这是真的:)

这里的一些代码的默认值enableeventvalidation:

<select CssClass="textoLightbox" id="selectPais" onchange="cambiarCiudad()"></select> 
<asp:HiddenField runat="server" ID="hdnPaisSeleccionado" /> 

<select CssClass="textoLightbox" id="selectCiudad" onchange="guardarCiudad()"></select> 
<asp:HiddenField runat="server" ID="hdnCiudadSeleccionada" /> 


<script language="javascript" type="text/javascript"> 
$(document).ready(function() { 
    ImprimirPais("selectPais"); 
    var dropPais = document.getElementById("selectPais"); 
    var dropCiudad = document.getElementById("selectCiudad"); 
    dropPais.value = "USA"; 
    print_state('selectCiudad', dropPais.selectedIndex) 
    dropCiudad.value = "California"; 
    document.getElementById("<%=hdnPaisSeleccionado.ClientID%>").value = "USA"; 
    document.getElementById("<%=hdnCiudadSeleccionada.ClientID%>").value = "California"; 

}); 

//Repopula el combo de las ciudades cuando es cambiado el pais. 
function cambiarCiudad() { 
    var dropPais = document.getElementById("selectPais"); 
    //Vacia ciudad 
    document.getElementById('selectCiudad').options.length = 0; 
    //Repopula ciudad de acuerdo al pais 
    print_state('selectCiudad', dropPais.selectedIndex); 
    //Guarda Pais 
    document.getElementById("<%=hdnPaisSeleccionado.ClientID%>").value = dropPais.value; 
    //Guarda Ciudad 
    guardarCiudad(); 
} 

function guardarCiudad() { 
    var dropCiudad = document.getElementById("selectCiudad"); 
    document.getElementById("<%=hdnCiudadSeleccionada.ClientID%>").value = dropCiudad.value; 
}