我在fancybox中有一个注册表单作为内联内容,并且可以在所有站点中访问它,因为链接在母版页中。
在注册表上我有两个下拉列表,一个用于国家,另一个用于城市。当用户更改国家/地区时,城市下拉列表会刷新为之前选择的国家/地区。来自国家和城市的所有数据都来自脚本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 = false。问题是我必须在每个页面上都这样做,因为fancybox在整个站点中,我读它并不是最好的安全实践。其他选择是,作为例外抛出,使用两个下拉列表的客户管理员注册每个选项,这将是令人厌倦的,因为有超过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 :(得分:0)
我最终使用纯html选择控件并将两个值保存在两个hiddenField中。有了这个,我可以使用默认值true来保存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;
}