gpt4 book ai didi

ASP.NET ListView 分页 : Invalid viewstate

转载 作者:行者123 更新时间:2023-12-02 13:00:53 25 4
gpt4 key购买 nike

我有一个 ListView 控件,如下所示(为了在此处发布,我已从 ItemTemplate 中删除了值):

<asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource">
<LayoutTemplate>
<div id="requests" runat="server">
<asp:Panel runat="server" id="itemPlaceholder"></asp:Panel>
</div>
<asp:DataPager runat="server" ID="DataPager" PageSize="3">
<Fields>
<asp:NumericPagerField ButtonCount="10" PreviousPageText="<--" NextPageText="-->" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div ID="itemPlaceholder" class="request" runat="server">
<asp:LinkButton ID="button" runat="server" Text='...' CommandName="..."
CommandArgument='...' OnClick="..."
style="...">
</asp:LinkButton> -
</div>
</ItemTemplate>
</asp:ListView>

此 ListView 作为用户控件 (.ascx) 存在,我已将其嵌入到 ASPX 网页中。

正如我所料,当网页加载时,对于包含 9 个项目的列表,我会得到 3 个页面,每页 3 个项目。

当我单击转到下一页时,该页面会正确加载下一组项目...但只持续了很短的一秒钟。然后奇怪的事情发生了。该页面将其自身的副本嵌入页面内 6 次,每次都位于页面内表单上的一个字段下方。

如果我随后尝试转到下一页或上一页,则会出现 ASP.NET 服务器错误:

The state information is invalid for this page and might be corrupted.

在堆栈跟踪中,它显示以下错误:

FormatException: The input is not a valid Base-64 string as it contains a non-base character, more than two padding characters, or a non-white space character among the padding characters.

ViewStateException: Invalid viewstate.

我能够在我的浏览器 IE8 和 Chrome 上复制这一点。

最佳答案

你使用listview事件OnPagePropertiesChanging

像这样

 <asp:ListView ID="lvCustomers" runat="server"   GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1" OnPagePropertiesChanging="OnPagePropertiesChanging">

在 aspx.cs 中

protected void OnPagePropertiesChanging(object sender,PagePropertiesChangingEventArgs e)
{
(lvCustomers.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
this.BindListView();
}

BindListView()是绑定(bind) ListView 的方法

visit this link for example

希望对你有帮助

关于ASP.NET ListView 分页 : Invalid viewstate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21601375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com