2012-08-10 118 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; 
}