在更新面板中更新列表视图并在母版页上回发

update listview in updatepanel and postback on masterpage

我们有这个列表视图的更新面板。

<asp:UpdatePanel ID="searchResultUpdate" runat="server">
            <Triggers><asp:AsyncPostBackTrigger ControlID="submitBT"/></Triggers>
            <ContentTemplate>
                <div id="status" runat="server" />
                <asp:ListView ID="searchResultLV" runat="server" OnItemCommand="searchResultLV_ItemCommand" DataKeyNames="Message_id" OnItemDeleting="searchResultLV_ItemDeleting">
                    <LayoutTemplate>
                        <table class="table table-hover">
                            <tr runat="server" id="itemPlaceholder" />
                        </table>
                    </LayoutTemplate>
                    <ItemTemplate>
                    </ItemTemplate>
                </asp:ListView>
            </ContentTemplate>
        </asp:UpdatePanel>

使用 searchResultLV.DataBind() 更新列表视图后;在 partial postback 中点击相应 master.page

中的这个按钮
<button id="LogoutAnchor" runat="server" onserverclick="LogoutAnchor_ServerClick" class="btn btn-default btn-flat">Sign out</button>

函数(LogoutAnchor_ServerClick)调用前发生错误:

[ArgumentException: 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.]

这是一个错误吗?我们不能在服务器上使用部分回发和完全回发吗?

  1. Page_Load事件中的所有代码移动如下。

    protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { // all your code here which should be executed only once } }

    1. 在此处进行以下更改。

    <%@ Page EnableEventValidation="false" %>