【问题标题】:ASP.NET updatepanel + invalid postbackASP.NET 更新面板 + 无效回发
【发布时间】:2010-02-23 18:00:34
【问题描述】:

我有以下非常简单的形式:

<asp:UpdatePanel ID="ClaimRewardsForm" runat="server">
    <ContentTemplate>
        <span class="largeBold">Select jacket weight:</span><br />
        <asp:RadioButtonList runat="server" ID="JacketWeight">
            <asp:ListItem Value="Lightweight" Text="Lightweight (fleece)" />
            <asp:ListItem value="Heavyweight" Text="Heavyweight (cotton)" />                                
        </asp:RadioButtonList>
        <br />
        <span class="largeBold">Select size:</span><br />
        (Men's sizes only)<br />
        <asp:DropDownList ID="JacketSize" runat="server">
            <asp:ListItem Value="Small" Text="Small" />
            <asp:ListItem Value="Medium" Text="Medium" />
            <asp:ListItem Value="Large" Text="Large" />
        </asp:DropDownList><br />
        <br />
        <asp:ImageButton ID="SubmitButton" runat="server" ImageUrl = "~/Content/Images/submitButton.png" onclick="SubmitButton_Click" />
    </ContentTemplate>
</asp:UpdatePanel>       

在我的按钮的点击处理程序中,我有:

protected void SubmitButton_Click(object sender, EventArgs e)
{
    if (IsValid)
    {
        using (var work = UnitOfWorkFactory.Create())
        {
            var id = new Guid(Session["id"].ToString());
            var account = UserAccounts.Get(id);

            if (account == null)
                throw new Exception("Invalid user account id.");

            account.RewardInfo.Clear();
            account.RewardInfo.Add(new RewardInfo()
            {
                UserAccount = account,
                JacketWeight = JacketWeight.SelectedValue,
                JacketSize = JacketSize.SelectedValue
            });

            work.Commit();
        }

        //ClaimRewardsForm.Update();
        //ScriptManager.RegisterStartupScript(this, GetType(),
        //    "confirmation", "ClaimRewards.showConfirmation();", true);
    }
}

我没有以任何方式修改表单字段,但我仍然收到以下错误:

505|error|500|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.|

由于我在回发期间根本没有修改控件,所以我终其一生都无法弄清楚为什么它的行为就像我已经修改过一样。有什么想法吗?

【问题讨论】:

标签: asp.net updatepanel


【解决方案1】:

这个人here 是你的罪魁祸首。如果您了解安全风险,您必须弄清楚您发布的内容会导致它阻止请求或禁用 EventValidation。

我在您发布的代码中看不到任何内容,但选项值中的 肯定会与它混淆。

【讨论】:

    【解决方案2】:

    我太傻了。我正在使用 DropDownList 适配器来允许我的列表中的选项组元素,但这导致了无效的回发,因为它在后台修改了列表中的元素,而没有为事件验证注册修改后的值。我修改了适配器以执行注册,现在它工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多