背景
我有一个 ASP.net UserControl,它是一个简单的用户输入表单。它使用 UpdatePanel 和 UpdaetProgress 在单击提交后显示“工作”gif。我们收到报告称,提交按钮有时在 FireFox、IE 8 和 Safari 中不起作用。在调查时,我无法在 IE 中重现任何问题,但发现在 FireFox 中,提交按钮出现以下脚本错误,该错误阻止了回发:
Error: Sys.WebForms.PageRequestManagerServerErrorException: 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.
Source File: http://localhost:1127/ScriptResource.axd?d=ZYU-uPMJ_AcQgBrmkW_WO13JlNZSAb9cMptxJsQIH1LnA8NC31pa7PAk8l5lYCB8LDDwft7xwh7Z107MKgt7KHHBeQaeEncnAFKLJ04CaHgelsuOOv072-1ZBvMW7N_x0&t=3693a5e0
Line: 1111
问题
为了找出导致错误的原因,我逐渐削减了代码,直到几乎没有剩余。我发现,当我从 UpdatePanel 中的 DropDownList 中进行选择时,该按钮会出现此错误(仅在 FireFox 中)。如果我删除 DropDownList、不进行选择或删除 UpdatePanel,则提交按钮会正确发回(其中任何一项)。
示例
创建一个 ASP.net 3.5 项目并将以下代码放入 aspx 页面中。在后面的代码中的 Page_Load 或 OnClick 事件处理程序中设置断点。运行它,从 DropDownList 中进行选择,然后单击提交。请注意,未命中断点。
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<div id="Div1" class="form-layout membership payment">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline">
<contenttemplate>
<table cellpadding="0" cellspacing="0" border="0" class="form_table payment">
<tr>
<th align="right" valign="top">
State <span class="reqd">*</span>
</th>
<td>
<asp:DropDownList Width="75px" ID="ddlState" CssClass="txt" runat="server" AutoPostBack="false">
<asp:ListItem Value="" Text="--Select--" />
<asp:ListItem>AB
</asp:ListItem>
<asp:ListItem>AL
</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<div class="clear-left pad-bottom">
</div>
<asp:Label ID="lblCreditCardError" CssClass="creditCardError" runat="server">
</asp:Label>
<table cellpadding="0" cellspacing="0" border="0" class="form_table">
<tr>
<th align="right" valign="top">
</th>
<td>
<asp:HiddenField ID="HFSubmitForm" runat="server" Value="0" />
<asp:Button ID="btnTest" runat="server" OnClick="btnSubmitCC_Click" />
</td>
</tr>
</table>
</contenttemplate>
</asp:UpdatePanel>
</div>
</div>
</form>
我认为使用标记无论如何都不重要,但我尝试使用 Page_Load 方法中的 if(!IsPostBack) block 中的绑定(bind)将项目添加到 DropDownList,但它没有改变任何内容。
最佳答案
我不确定这是否会导致您的问题,但请尝试正确设置 DropDownList-Items 的格式:
<asp:DropDownList Width="75px" ID="ddlState" CssClass="txt" runat="server" AutoPostBack="false">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="AB"></asp:ListItem>
<asp:ListItem Text="AL"></asp:ListItem>
</asp:DropDownList>
关于asp.net - UpdatePanel 中未修改的 DropDownList 导致 FireFox 中的事件验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7561452/