代码之家  ›  专栏  ›  技术社区  ›  Chris

ASP.NET UpdatePanel+回发无效

  •  0
  • Chris  · 技术社区  · 15 年前

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

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

    因为我在发帖过程中根本没有修改任何控件,所以我一辈子都无法弄明白为什么它会像我一样。有什么想法吗?

    2 回复  |  直到 15 年前
        1
  •  0
  •   DancesWithBamboo    15 年前

    这个家伙 here 是你的罪魁祸首。如果您了解安全风险,您必须弄清楚您要发布的内容,以使其阻止请求或禁用事件验证。

    我在您发布的代码中没有看到任何内容,但在选项值中肯定会弄乱代码。

        2
  •  0
  •   Chris    15 年前

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