【问题标题】:update listview in updatepanel and postback on masterpage更新更新面板中的列表视图和母版页上的回发
【发布时间】:2015-03-02 12:33:35
【问题描述】:

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

<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() 更新列表视图后;在部分回发中并在相应的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.]

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

【问题讨论】:

    标签: c# asp.net listview updatepanel


    【解决方案1】:
    1. 如下移动Page_Load事件中的所有代码。

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

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

      &lt;%@ Page EnableEventValidation="false" %&gt;

    【讨论】:

    • 您提供的解决方案确实有效,但是我们选择了另一种方法,因为这种解决方案会损害我们的安全性。仔细观察,master.page 中的按钮并没有从与第一个按钮相同的 asp:Form 调用回发。所以,我们让第二个按钮调用另一个按钮,它在同一个表单中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    相关资源
    最近更新 更多