我正在爲我的大學項目製作一個網站。 該項目是網站,從Web服務獲取一切。 有人可以告訴發生了什麼事情,我如何解決它?問題:無法加載視圖狀態
在我的其中一個頁面上,我有ListView控件來顯示產品項目和Pager在同一頁面上。 在第一次頁面呈現良好,並顯示一切。當我在下一頁點擊尋呼機,它的重載頁面,但不顯示第二頁,而顯示相同的數據,如果我推一次話,我剛開:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
我的產品頁面我安靜簡單:
<asp:ListView ID="lv_ProductList" runat="server" DataKeyNames="product_id">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
<br />
<br />
<asp:DataPager ID="pageTopics" runat="server" PageSize="8" PagedControlID="lv_ProductList" >
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="true" ShowNextPageButton="false" ButtonCssClass="span" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="false" ShowNextPageButton="true" ShowLastPageButton="false" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div class="item">
<img src="images/pic_1.jpg" width="91" height="105" alt="iPod" class="left" />
<h3><a href="http://www.justwebtemplates.com"><%# Eval("product_name") %></a></h3>
<p><%# Eval("product_desc").ToString().Substring(0,90) + "..." %> </p>
<div><a href="http://www.freewebsitetemplates.com" class="details">details</a> <a href="http://www.freewebsitetemplates.com" class="addtocart">add to cart</a></div>
<div class="divider"></div>
</div>
</ItemTemplate>
<EmptyDataTemplate>No products found</EmptyDataTemplate>
<EmptyItemTemplate>No products found</EmptyItemTemplate>
</asp:ListView>
而且在我後面的代碼有:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getProductsList();
}
}
public void getProductsList()
{
Store.Service myProducts = new Store.Service();
var products = myProducts.getProductList();
lv_ProductList.DataSource = products;
lv_ProductList.DataBind();
}
和Web服務:
[WebMethod]
public List<ws_product> getProductList()
{
using (DataClassesDataContext myProducts = new DataClassesDataContext())
{
var productList = from p in myProducts.ws_products
select p;
return productList.ToList();
}
}
有人可以告訴發生了什麼事嗎? 此外,如果我把尋呼機外ListView,那麼我不會收到錯誤,但是,如果我點擊下一頁鏈接它顯示相同的數據集。
我該如何解決? 預先感謝您。