繁体   English   中英

ASP.NET UpdatePanel +无效的回发

[英]ASP.NET updatepanel + invalid postback

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

<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.|

由于我在回发过程中根本不修改控件,因此我一生都无法弄清为什么它像我一样起作用。 有什么想法吗?

这家伙在这里是你的罪魁祸首。 如果您了解安全隐患,则必须弄清楚要发布的内容以使其阻止请求或禁用EventValidation。

我看不到您发布的代码中的任何内容,但是选项值中的<>肯定使它混乱。

愚蠢的我。 我正在使用DropDownList适配器在列表中允许使用optiongroup元素,但这会导致无效的回发,因为它会在后台修改列表中的元素,而不会注册用于事件验证的修改后的值。 我修改了适配器以执行注册,现在可以正常工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM