背景
我有一个ASP.net UserControl,它是一个简单的用户输入表单。它使用UpdatePanel和UpdaetProgress在单击submit后显示“工作”gif。据报道,提交按钮有时不会在FireFox、IE8和Safari中执行任何操作。在查看时,我无法重现IE中的任何问题,但发现在FireFox中,submit按钮得到了以下脚本错误,从而阻止了回发:
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问题
为了找出导致错误的原因,我逐渐缩减了代码,直到几乎一无所有。我发现,当我从DropDownList中选择UpdatePanel时,按钮会得到这个错误(仅在FireFox中)。如果我删除DropDownList,不要做选择,或者删除UpdatePanel,提交按钮将正确回发(其中任何一个)。
示例
创建一个ASP.net 3.5项目,并将代码放在aspx页面中。在代码后面的Page_Load或OnClick事件处理程序中设置一个断点。运行它,从DropDownList中选择,然后从ClickSubmit中选择。注意,断点没有命中。
<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>无论如何,我认为使用标记并不重要,但是我尝试使用在DropDownList方法中的if(!IsPostBack)块中的绑定将这些项添加到Page_Load中,但是它没有改变任何东西。
发布于 2011-09-26 21:59:25
我不确定这是否导致了您的问题,但请尝试正确设置DropDownList-项目的格式:
<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>发布于 2011-09-26 22:12:53
首先,您在UpdatePanel下缺少了以下内容:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnTest" />
</Triggers>第二..。我相信,要么在代码隐藏中绑定列表选项,要么关闭此页面的事件验证,或者为每个选项调用RegisterForEventValidtion()。我对最后这个有点粗略,因为我从来没有真正使用过它。通过简单地添加AsyncPostBackTrigger,然后将DDL绑定到代码背后,我就能够让您的代码工作起来。
最后,您可能只是在调试时忽略了这些未处理的异常,因为您期望从浏览器中得到一些东西.但实际上,浏览器应该认为什么都没有发生。拉出EventViewer以查看未处理的ASP.NET异常。在获得事件处理程序之前,异常正在停止执行。
发布于 2011-09-28 14:47:01
@啊哈,这就解释了这一点。(在回答中回答,这样我就可以显示代码并确保您的答案是清晰的)下面是ASP.NET发送给浏览器的内容:
<SELECT style="WIDTH: 75px" id=ddlState class=txt name=ddlState>
<OPTION selected value="">--Select--</OPTION>
<OPTION value="AB ">AB</OPTION>
<OPTION value="AL ">AL</OPTION>
</SELECT>&#l3;&#l0是/r/n。在IE中,上面显示的整个值都包含在FireFox中,但在FireFox中它被缩小为一个空格(例如,"AB ")。当它被传递回服务器时,它会看到所选选项的值不是最初包含的值。我已经将发送的HTML与FireFox中的HTML进行了比较,但我查看了Visualizer的中的上述HTML,它也删除了它们,因此我没有注意到其中的区别。
https://stackoverflow.com/questions/7561452
复制相似问题