2010-06-18 30 views
5

OK vừa mới bắt đầu gặp lỗi này và tôi không chắc chắn tại sao. Tôi có một trang lưu trữ có listview và một bảng điều khiển với một usercontrol. Listview tải lên các bản ghi với một nút liên kết. Bạn nhấp vào nút liên kết để chỉnh sửa bản ghi cụ thể - được tải lên trong formview (trong usercontrol) mà đi vào chế độ chỉnh sửa. Sau khi cập nhật xảy ra trong formview tôi kích hoạt một sự kiện mà trang lưu trữ của tôi đang lắng nghe. Các trang lưu trữ sau đó rebinds listview để hiển thị các dữ liệu cập nhật. Đây là tất cả bên trong một updatepanel.Không thể tải viewstate

Vì vậy, đây mọi công việc - nhưng khi tôi sau đó đi đến bấm vào một linkbutton khác nhau tôi nhận được báo lỗi dưới đây:

Message: Sys.WebForms.PageRequestManagerServerErrorException: 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. 

Bất kỳ đề xuất về cách khắc phục?

Chế độ xem danh sách của tôi dường như được khôi phục thành công - Tôi có thể xem dữ liệu đã thay đổi của mình .. Tôi không biết tại sao nó phàn nàn về chế độ xem khi tôi nhấp vào nút liên kết. Hoặc là có một cách tốt hơn để cập nhật dữ liệu trong listview của tôi? Listview và formview của tôi bị ràng buộc với các nguồn objectdata (trong trường hợp quan trọng)

Cảm ơn sự giúp đỡ!

Đây là codebehind trong tầm kiểm soát của tôi. Những người khác đã nhận xét về lỗi này là liên quan đến việc thay đổi phương thức formview nhưng đã thử một vài thay đổi nhưng không thành công:

public partial class UserControls_RatesEditDate : System.Web.UI.UserControl 
{ 

    public delegate void EditDateRateEventHandler(DateTime theDateTime); 
    public event EditDateRateEventHandler EditDateRateSelected; 

    public delegate void UpdateDateRateEventHandler(); 
    public event UpdateDateRateEventHandler EditDateRateUpdated; 

    public int PropertyID { get; set; } 
    public int AccommodationTypeID { get; set; } 
    public DateTime TheDateTime { get; set; } 
    public PropertyCMSRate Rate { get; set; } 

    // display filters 
    public bool DisplayMTABuy { get; set; } 
    public bool DisplayMTASell { get; set; } 
    public bool DisplayAffiliate { get; set; } 
    public bool DisplayWeekly { get; set; } 
    public bool DisplayThirtyDay { get; set; } 
    public bool DisplayFlexi { get; set; } 

    protected void Page_PreRender(object sender, EventArgs e) 
    { 
     if (Rate != null || TheDateTime != DateTime.MinValue) 
     { 
      if (TheDateTime == DateTime.MinValue) 
      { 
       frmViewRatesDate.DataSource = new List<PropertyCMSRate> { Rate }; 
      } 
      else 
      { 
       PropertyCMSRateItemDs.SelectParameters["propertyID"].DefaultValue = PropertyID.ToString(); 
       PropertyCMSRateItemDs.SelectParameters["accommodationTypeId"].DefaultValue = AccommodationTypeID.ToString(); 
       PropertyCMSRateItemDs.SelectParameters["theDateTime"].DefaultValue = TheDateTime.ToString(); 
       frmViewRatesDate.DataSourceID = "PropertyCMSRateItemDs"; 

       frmViewRatesDate.ChangeMode(FormViewMode.Edit); 
      } 

      frmViewRatesDate.DataBind(); 

      if (frmViewRatesDate.CurrentMode == FormViewMode.Edit) 
      { 
       ((HiddenField)frmViewRatesDate.FindControl("hdnPropertyID")).Value = PropertyID.ToString(); 
       ((HiddenField)frmViewRatesDate.FindControl("hdnAccommTypeID")).Value = AccommodationTypeID.ToString(); 

      } 

     } 
    } 

    protected void lnkEditDate_Click(object sender, EventArgs e) 
    { 
     if (EditDateRateSelected != null) 
      EditDateRateSelected(Convert.ToDateTime(((LinkButton)frmViewRatesDate.Row.FindControl("lnkEditDate")).Text)); 

    } 

    protected void btnUpdate_Click(object sender, EventArgs e) 
    { 

     if (Page.IsValid) 
     { 
      if (EditDateRateUpdated != null) 
       EditDateRateUpdated(); 
     } 

    } 

    protected void frmViewRatesDate_ItemCommand(object sender, FormViewCommandEventArgs e) 
    { 
     if (e.CommandName == "Update") 
     { 
      PropertyCMSRateItemDs.UpdateParameters["propertyId"].DefaultValue = ((HiddenField)frmViewRatesDate.FindControl("hdnPropertyID")).Value; 
      PropertyCMSRateItemDs.UpdateParameters["accommodationTypeId"].DefaultValue = ((HiddenField)frmViewRatesDate.FindControl("hdnAccommTypeID")).Value; 
      PropertyCMSRateItemDs.UpdateParameters["minStay"].DefaultValue = ((DropDownList)frmViewRatesDate.FindControl("EditPriceMinStayList")).SelectedValue; 
     } 
    } 

    protected void PropertyCMSRateItemDs_Updated(object sender, ObjectDataSourceStatusEventArgs e) 
    { 

     if (EditDateRateUpdated != null) 
      EditDateRateUpdated(); 
    } 
} 

OK ở đây là trang aspx của tôi - xin lỗi nhận ra rằng có thể giúp đỡ sau khi tôi rời văn phòng để lấy thức ăn. :) đã đặt một bình luận trước listview của tôi có chứa từ đó ..

<%@ MasterType VirtualPath="~/Properties-Cms/AddEdit.master" %> 
<%@ Register Src="../UserControls/RatesEditDate.ascx" TagName="RatesEditDate" TagPrefix="uc1" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <Triggers> 
     </Triggers> 
     <ContentTemplate> 
       <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Main" /> 
      <div class="bluebox"> 
       <asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="AddAccommodationType" /> 
       <asp:CustomValidator ID="DisplayPriceValidation" Display="Dynamic" runat="server" OnServerValidate="DisplayPrice_Validated" 
           ValidationGroup="Main" ErrorMessage="Please ensure you have selected Accommodation and selected a valid display rates option"> 
          </asp:CustomValidator> 
       <div class="col33"> 
        <!-- accommodation --> 
        <div class="field"> 
         <asp:Label ID="Label1" runat="server" Text="Select Accommodation" AssociatedControlID="Accommodations1" /> 
         <asp:DropDownList ID="Accommodations1" runat="server" AutoPostBack="true" DataTextField="AccommodationTypeDescription" 
          DataValueField="Id" OnDataBound="Accommodations1_DataBound" OnSelectedIndexChanged="Accommodations1_SelectedIndexChanged" 
          Width="200px" DataSourceID="AccommodationDs"> 
         </asp:DropDownList> 
         <asp:ObjectDataSource ID="AccommodationDs" runat="server" OldValuesParameterFormatString="original_{0}" 
          SelectMethod="ListByPropertyId" TypeName="Shared.MtaLib.Bll.PropertyAccommodationController"> 
          <SelectParameters> 
           <asp:Parameter Name="PropertyId" Type="Int32" /> 
          </SelectParameters> 
         </asp:ObjectDataSource> 
        </div> 
       </div> 
       <!-- middle column --> 
       <div class="col33"> 
        <ul style="list-style-type: none;"> 
         <li> 
          <asp:Label ID="Label100" runat="server" Text="Accommodation" AssociatedControlID="lblAccom" />&nbsp;<asp:Label 
           ID="lblAccom" runat="server" Text="" /></li> 
         <li> 
          <asp:Label ID="Label101" runat="server" Text="Local Label" AssociatedControlID="lblLocalLabel" />&nbsp;<asp:Label 
           ID="lblLocalLabel" runat="server" Text="" /></li> 
        </ul> 
       </div> 
       <!--Right hand side Level 1 --> 
       <div class="col33"> 
        <asp:Button runat="server" ID="btnAddAccommodation" Text="Add Accommodation" OnClick="btnAddAccommodation_Click" /><br /> 
        <br /> 
        <asp:LinkButton runat="server" ID="lnkEditAccommodation" Text="View/Edit available Accommodations" 
         OnClick="lnkEditAccommodation_Click" /> 
        <br /> 
       </div> 
       <div style="clear: both;"> 
       </div> 
      </div> 
      <!--Left hand side Level 2 --> 
      <asp:Panel runat="server" ID="pnlViewAccommodationRatesDates"> 
       <div style="clear: both;" /> 
       <div class="box"> 
        <div class="col40"> 
         Display rates Range<br /> 
         <asp:RadioButton ID="ViewRange" runat="server" GroupName="DisplayDate" Checked="true" /> 
         <asp:Label runat="server" ID="Label5" AssociatedControlID="txtDisplayFrom" Text="From" /> 
         <asp:TextBox ID="txtDisplayFrom" runat="server"></asp:TextBox> 
         <asp:Label runat="server" ID="Label6" AssociatedControlID="txtDisplayTo" Text="To" /> 
         <asp:TextBox ID="txtDisplayTo" runat="server"></asp:TextBox> 
        </div> 
        <div class="col20"> 
         <br /> 
         <asp:RadioButton ID="ViewRange1" runat="server" GroupName="DisplayDate" Text="Next 1 month" /><br /> 
         <asp:RadioButton ID="ViewRange3" runat="server" GroupName="DisplayDate" Text="Next 3 month" /><br /> 
         <asp:RadioButton ID="ViewRange6" runat="server" GroupName="DisplayDate" Text="Next 6 month" /> 
        </div> 
        <div class="col20"> 
         Show<br /> 
         <asp:CheckBox ID="chkDisplayMTABuy" runat="server" Text="MTA Buy" Checked="true" /><br /> 
         <asp:CheckBox ID="chkDisplayMTASell" runat="server" Text="MTA Sell" Checked="true" /><br /> 
         <asp:CheckBox ID="chkDisplayAffiliateNett" runat="server" Text="Affiliate Nett" Checked="true" /><br /> 
         <asp:CheckBox ID="chkDisplayWeekly" runat="server" Text="Weekly" Checked="true" /><br /> 
         <asp:CheckBox ID="chkDisplay30Day" runat="server" Text="30 Day" Checked="true" /><br /> 
         <asp:CheckBox ID="chkDisplayFlexi" runat="server" Text="Flexi" Checked="true" /> 
        </div> 
        <div class="col20"> 
         <br /> 
         <br /> 
         <br /> 
         <asp:Button ID="btnDisplayRates" runat="server" Text="Display Rates" OnClick="btnDisplayRates_Click" /> 
         <br /> 
         <br /> 
         <asp:LinkButton ID="lnkAddEditRate" runat="server" Text="Add/Edit Rates" OnClick="lnkAddEditRate_Click" /> 
        </div> 
        <div style="clear: both;" /> 
       </div> 
      </asp:Panel> 
      <!-- hidden panel removed as I'm out of characters --> 
      <!-- Listview containing user control.. usercontrol has formview with a linkbutton --> 
      <asp:Panel runat="server" ID="pnlViewAccommodationRates" Visible="false"> 
       <div class="propertyaddedit_ratesbox"> 
        <fieldset> 
         <legend>Click on individual dates to edit</legend> 
         <asp:Panel ID="Panel5" runat="server" ScrollBars="Vertical" Height="400"> 
          <asp:ListView ID="PropertyAccommodationRates1" runat="server" DataSourceID="PropertyCMSRateListDs" 
           ItemPlaceholderID="itemsGoHere" OnItemDataBound="PropertyAccommodationRates1_ItemDataBound" 
           GroupItemCount="7" GroupPlaceholderID="groupsGoHere"> 
           <GroupTemplate> 
            <tr> 
             <asp:PlaceHolder runat="server" ID="itemsGoHere" /> 
            </tr> 
           </GroupTemplate> 
           <ItemTemplate> 
            <td> 
             <uc1:RatesEditDate ID="RatesViewDate1" runat="server" OnEditDateRateSelected="RatesEditDate1_EditDateRateSelected" 
              OnEditDateRateUpdated="RatesEditDate1_EditDateRateUpdated" /> 
            </td> 
           </ItemTemplate> 
           <LayoutTemplate> 
            <table width="525px" cellspacing="2"> 
             <tr class="propertyaddedit_gridViewRates"> 
              <th class="propertyaddedit_ratesGrid"> 
               Monday 
              </th> 
              <th class="propertyaddedit_ratesGrid"> 
               Tuesday 
              </th> 
              <th class="propertyaddedit_ratesGrid"> 
               Wednesday 
              </th> 
              <th class="propertyaddedit_ratesGrid"> 
               Thursday 
              </th> 
              <th class="propertyaddedit_ratesGrid"> 
               Friday 
              </th> 
              <th class="propertyaddedit_ratesGrid"> 
               Saturday 
              </th> 
              <th class="propertyaddedit_ratesGrid"> 
               Sunday 
              </th> 
             </tr> 
             <tr> 
              <asp:PlaceHolder runat="server" ID="groupsGoHere" /> 
             </tr> 
            </table> 
           </LayoutTemplate> 
          </asp:ListView> 
          <asp:ObjectDataSource ID="PropertyCMSRateListDs" runat="server" SelectMethod="ListPropertyCMSRates" 
           TypeName="Shared.MtaLib.Bll.PropertyRateController" OnSelecting="PropertyCMSRateListDs_Selecting"> 
           <SelectParameters> 
            <asp:Parameter Name="propertyId" Type="Int32" /> 
            <asp:Parameter Name="accommodationTypeId" Type="Int32" /> 
            <asp:Parameter Name="minDateTime" Type="DateTime" /> 
            <asp:Parameter Name="maxDateTime" Type="DateTime" /> 
            <asp:Parameter Name="fillMondays" Type="Boolean" DefaultValue="true" /> 
           </SelectParameters> 
          </asp:ObjectDataSource> 
         </asp:Panel> 
        </fieldset> 
       </div> 
      </asp:Panel> 



      <div style="clear: both;"> 
      </div> 
      <!-- this is the usercontrol where the edit occurs --> 
      <div runat="server" id="divEditRate" visible="true"> 
       <uc1:RatesEditDate ID="RatesEditDate1" runat="server" /> 
      </div> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
</asp:Content> 

điều khiển người dùng của tôi:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RatesEditDate.ascx.cs" 
    Inherits="UserControls_RatesEditDate" %> 
<asp:FormView ID="frmViewRatesDate" runat="server" Height="50px" Width="125px" OnItemCommand="frmViewRatesDate_ItemCommand" 
    DataKeyNames="TheDateTime"> 
    <ItemTemplate> 
     <asp:LinkButton ID="lnkEditDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TheDateTime", "{0:dd/MM/yyyy}") %>' 
      OnClick="lnkEditDate_Click" /> 
     <asp:Literal ID="Literal1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTABuyRateDaily", "{0:n}") %>' 
      Visible='<%# DisplayMTABuy %>' /> 
     <asp:Literal ID="Literal2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTASellRateDaily", "{0:n}") %>' 
      Visible='<%# DisplayMTASell %>' /> 
     <asp:Literal ID="Literal3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AffiliateNettDaily", "{0:n}") %>' 
      Visible='<%# DisplayAffiliate %>' /> 
     <asp:Literal ID="Literal4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTABuyRateWeekly", "{0:n}") %>' 
      Visible='<%# DisplayWeekly %>' /> 
     <asp:Literal ID="Literal5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTASellRateWeekly", "{0:n}") %>' 
      Visible='<%# DisplayWeekly %>' /> 
     <asp:Literal ID="Literal6" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AffiliateNettWeekly", "{0:n}") %>' 
      Visible='<%# DisplayWeekly %>' /> 
     <asp:Literal ID="Literal7" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ThirtyDay", "{0:n}") %>' 
      Visible='<%# DisplayThirtyDay %>' /> 
     <asp:Literal ID="Literal8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Flexi", "{0:n}") %>' 
      Visible='<%# DisplayFlexi %>' /> 
    </ItemTemplate> 
    <EditItemTemplate> 
     <div class="field"> 
      <asp:Literal ID="TheDate" runat="server" Text='<%# Bind("TheDateTime", "{0:dd/MM/yyyy}") %>' /> 
     </div> 
     <div class="field"> 
      <asp:Label ID="Label1" Text="MTA buy rate" AssociatedControlID="MTABuyRate1" runat="server" /><asp:TextBox 
       ID="MTABuyRate1" runat="server" Text='<%# Bind("MTABuyRateDaily", "{0:n}")%>' /> 
      <asp:CompareValidator ID="MTABuyRateValidator" runat="server" Type="Currency" ControlToValidate="MTABuyRate1" 
       Operator="GreaterThan" ValueToCompare="0" ErrorMessage="" Display="Dynamic" ValidationGroup="EditPrice"> 
       <asp:Image ID="Image8" SkinID="ValidationErrorImage" runat="server" /> 
      </asp:CompareValidator> 
      <asp:RequiredFieldValidator ID="MTABuyRateValidator2" runat="server" ControlToValidate="MTABuyRate1" 
       ErrorMessage="" Display="Dynamic" ValidationGroup="EditPrice"> 
       <asp:Image ID="Image33" SkinID="ValidationErrorImage" runat="server" /> 
      </asp:RequiredFieldValidator> 
     </div> 
     <!-- similar items removed due to character restriction --> 
     <div class="field"> 
      <asp:Label ID="Label6" Text="Total PAX" runat="server" AssociatedControlID="TotalPax1" /> 
      <asp:CompareValidator ID="TotalPaxValidator1" runat="server" ControlToValidate="TotalPax1" 
       Operator="NotEqual" ValueToCompare="0" ErrorMessage="Please choose a non zero Total Pax " 
       Display="Dynamic" ValidationGroup="EditPrice"> 
       <asp:Image ID="Image15" SkinID="ValidationErrorImage" runat="server" /> 
      </asp:CompareValidator> 
      <asp:DropDownList ID="TotalPax1" runat="server"> 
       <asp:ListItem Value="0" /> 
       <asp:ListItem Value="1" /> 
       <asp:ListItem Value="2" /> 
       <asp:ListItem Value="3" /> 
       <asp:ListItem Value="4" /> 
       <asp:ListItem Value="5" /> 
       <asp:ListItem Value="6" /> 
       <asp:ListItem Value="7" /> 
       <asp:ListItem Value="8" /> 
       <asp:ListItem Value="9" /> 
       <asp:ListItem Value="10" /> 
      </asp:DropDownList> 
     </div> 
     <div class="field"> 
      <asp:Label runat="server" ID="Label15" AssociatedControlID="EditPriceMinStayList" 
       Text="Min stay (nights)" /> 
      <asp:CompareValidator ID="EditPriceMinStayListValidator1" runat="server" ControlToValidate="EditPriceMinStayList" 
       Operator="NotEqual" ValueToCompare="0" ErrorMessage="Please choose a non zero Min Stay" 
       Display="Dynamic" ValidationGroup="EditPrice"> 
       <asp:Image ID="Image6" SkinID="ValidationErrorImage" runat="server" /> 
      </asp:CompareValidator> 
      <!-- todo bind--> 
      <asp:DropDownList ID="EditPriceMinStayList" runat="server"> 
       <asp:ListItem Value="0" /> 
       <asp:ListItem Value="1" /> 
       <asp:ListItem Value="2" /> 
       <asp:ListItem Value="3" /> 
       <asp:ListItem Value="4" /> 
       <asp:ListItem Value="5" /> 
       <asp:ListItem Value="6" /> 
       <asp:ListItem Value="7" /> 
       <asp:ListItem Value="8" /> 
       <asp:ListItem Value="9" /> 
       <asp:ListItem Value="10" /> 
       <asp:ListItem Value="11" /> 
       <asp:ListItem Value="12" /> 
       <asp:ListItem Value="13" /> 
       <asp:ListItem Value="14" /> 
       <asp:ListItem Value="15" /> 
       <asp:ListItem Value="16" /> 
       <asp:ListItem Value="17" /> 
       <asp:ListItem Value="18" /> 
       <asp:ListItem Value="19" /> 
       <asp:ListItem Value="20" /> 
       <asp:ListItem Value="21" /> 
       <asp:ListItem Value="22" /> 
       <asp:ListItem Value="23" /> 
       <asp:ListItem Value="24" /> 
       <asp:ListItem Value="25" /> 
       <asp:ListItem Value="26" /> 
       <asp:ListItem Value="27" /> 
       <asp:ListItem Value="28" /> 
       <asp:ListItem Value="29" /> 
       <asp:ListItem Value="30" /> 
      </asp:DropDownList> 
     </div> 
     <div class="field"> 
      <%--<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" CommandName="Update" />--%> 
      <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" ValidationGroup="EditPrice" /> 
     </div> 
     <asp:HiddenField runat="server" ID="hdnPropertyID" /> 
     <asp:HiddenField runat="server" ID="hdnAccommTypeID" /> 
    </EditItemTemplate> 
</asp:FormView> 
<asp:ObjectDataSource ID="PropertyCMSRateItemDs" runat="server" SelectMethod="ListPropertyCMSRate" 
    TypeName="Shared.MtaLib.Bll.PropertyRateController" UpdateMethod="UpdatePropertyCMSRate" 
    OldValuesParameterFormatString="original_{0}" OnUpdated="PropertyCMSRateItemDs_Updated"> 
    <UpdateParameters> 
     <asp:Parameter Name="propertyId" Type="Int32" /> 
     <asp:Parameter Name="accommodationTypeId" Type="Int32" /> 
     <asp:Parameter Name="minStay" Type="Int32" /> 
     <asp:Parameter Name="TheDateTime" Type="DateTime" /> 
     <asp:Parameter Name="MTABuyRateDaily" Type="Decimal" /> 
     <asp:Parameter Name="MTASellRateDaily" Type="Decimal" /> 
     <asp:Parameter Name="AffiliateNettDaily" Type="Decimal" /> 
     <asp:Parameter Name="MTABuyRateWeekly" Type="Decimal" /> 
     <asp:Parameter Name="MTASellRateWeekly" Type="Decimal" /> 
     <asp:Parameter Name="AffiliateNettWeekly" Type="Decimal" /> 
     <asp:Parameter Name="ThirtyDay" Type="Decimal" /> 
     <asp:Parameter Name="Flexi" Type="Decimal" /> 
     <asp:Parameter Name="IsBreakfastIncluded" Type="Boolean" /> 
     <asp:Parameter Name="IsFairWarning" Type="Boolean" /> 
     <asp:Parameter Name="TotalPax" Type="Int32" /> 
     <asp:Parameter Name="original_TheDateTime" Type="DateTime" /> 
    </UpdateParameters> 
    <SelectParameters> 
     <asp:Parameter Name="propertyId" Type="Int32" DefaultValue="0" /> 
     <asp:Parameter Name="accommodationTypeId" Type="Int32" DefaultValue="0" /> 
     <asp:Parameter Name="theDateTime" Type="DateTime" /> 
    </SelectParameters> 
</asp:ObjectDataSource> 
+0

Điều khiển động duy nhất tôi có thể nghĩ đến - là do listview itemtemplate chứa điều khiển người dùng. Và khi tôi gọi một rebind trên listview nó sẽ khác với lần đầu tiên trang được tải. Nhưng tôi phải làm mới listview bằng cách nào đó để phản ánh dữ liệu mới. Hoặc vấn đề có liên quan đến bảng cập nhật không? – Jen

+0

Đã xóa bảng cập nhật của tôi và tôi vẫn gặp lỗi tương tự. Cũng đã cố gắng bình luận ra databind của danh sách của tôi xem và vẫn nhận được cùng một lỗi .. vì vậy rõ ràng là cái gì khác. – Jen

+0

Đã cố gắng đặt chế độ xem thành phố bị tắt trên cả chế độ xem danh sách của tôi và/hoặc chế độ xem biểu mẫu của tôi - và làm như vậy dẫn đến trang không hoạt động như mong muốn. Khi tôi nhấp vào nút liên kết của tôi, lưới sẽ mất các mục của nó .. hoặc điều khiển sẽ không được hiển thị trong chế độ chỉnh sửa. – Jen

Trả lời

1

Có vẻ như vấn đề của tôi liên quan đến chế độ xem và thay đổi chế độ.

Tôi đã kết thúc tạo một điều khiển người dùng thứ hai với một chế độ xem biểu mẫu chỉ có mẫu mục chỉnh sửa và tôi đặt chế độ mặc định để chỉnh sửa.Sử dụng cái này để chỉnh sửa, và cái gốc để xem tỷ lệ đã loại bỏ được lỗi của viewstate. Rõ ràng là không lý tưởng vì tôi không cần phải làm điều này - nhưng trong khi tôi cố gắng ép nó không chuyển sang chế độ chỉ đọc sau khi lưu các thay đổi - không có gì tôi đã thử sẽ ngăn chặn lỗi đó. Đã dành đủ thời gian để giải quyết vấn đề này - thời gian để tiếp tục !! Cảm ơn những đề xuất mặc dù mọi người :)

4

Thật khó để cung cấp cho bạn một câu trả lời chính xác mà không cần nhìn qua toàn bộ trang aspx của bạn, nhưng nói chung các vấn đề như thế này xảy ra khi bạn đang sửa đổi các phần tử đã bật chế độ xem bằng cách sử dụng javascript. Khi bạn đăng lại máy chủ của mình (ví dụ, nhấp vào nút liên kết), chế độ xem trên trang của bạn khác với chế độ xem mà máy chủ đang tìm kiếm, do đó, nó bị treo. Đây là một biện pháp an ninh.

Bạn có đang sử dụng AJAX thông qua bảng cập nhật không? Bạn có một số phần của trang trong bảng cập nhật và một số phần không? Có lẽ sự kiện của bạn đang cập nhật một số điều khiển chứ không phải những người khác.

Bạn có thể cung cấp phiên bản chú thích của trang ASPX mà chúng tôi có thể xem không?

2

Vấn đề này cũng là cơn ác mộng gần đây của tôi. Có nhiều khả năng có thể dẫn đến kết thúc với lỗi "Không tải viewstate". Hầu hết thời gian, nó liên quan đến các điều khiển được tạo động và các thuộc tính .Visible của các điều khiển có thể thay đổi thứ bậc của các điều khiển được thêm vào trang.

Theo hiểu biết của tôi, sự cố có thể xoay quanh các thuộc tính có thể nhìn thấy của các điều khiển. Hãy cố gắng loại bỏ các dữ liệu liên quan đến tài sản có thể nhìn thấy đầu tiên và xem nó như thế nào.

<asp:Literal ID="Literal1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTABuyRateDaily", "{0:n}") %>' 
     Visible='<%# DisplayMTABuy %>' /> 
    <asp:Literal ID="Literal2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTASellRateDaily", "{0:n}") %>' 
     Visible='<%# DisplayMTASell %>' /> 
    <asp:Literal ID="Literal3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AffiliateNettDaily", "{0:n}") %>' 
     Visible='<%# DisplayAffiliate %>' /> 
    <asp:Literal ID="Literal4" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTABuyRateWeekly", "{0:n}") %>' 
     Visible='<%# DisplayWeekly %>' /> 
    <asp:Literal ID="Literal5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "MTASellRateWeekly", "{0:n}") %>' 
     Visible='<%# DisplayWeekly %>' /> 
    <asp:Literal ID="Literal6" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AffiliateNettWeekly", "{0:n}") %>' 
     Visible='<%# DisplayWeekly %>' /> 
    <asp:Literal ID="Literal7" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ThirtyDay", "{0:n}") %>' 
     Visible='<%# DisplayThirtyDay %>' /> 
    <asp:Literal ID="Literal8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Flexi", "{0:n}") %>' 
     Visible='<%# DisplayFlexi %>' /> 
+0

Cảm ơn đề xuất - nhưng không có niềm vui. Vẫn gặp lỗi sau khi xóa tất cả các thuộc tính hiển thị trên các chữ. – Jen

5

Tôi đã chiến đấu với vấn đề này trong vài giờ và vài ngày. Không ai trong số các câu trả lời tôi đã tìm thấy hoàn toàn giải quyết vấn đề của tôi, nhưng cuối cùng tôi đã tìm thấy một giải pháp.

Kịch bản của tôi như sau. Tôi có GridView và FormView. Đây là hai chế độ xem của điều khiển MultiView. Tôi hiển thị danh sách dữ liệu trong GridView. Nút chỉnh sửa của tôi chuyển sang FormView vì có nhiều trường mà tôi muốn chỉnh sửa hơn sẽ phù hợp với một đường ngang trên khung nhìn (không có cuộn ngang).

Nếu tôi hủy từ chế độ chỉnh sửa của FormView và quay lại GridView (tôi sử dụng sự kiện OnClick để thực hiện việc này), lần sau khi xảy ra postback, tôi gặp lỗi ViewState.

Nếu tôi hủy từ chế độ chỉnh sửa của FormView và chỉ cần chuyển sang chế độ ReadOnly và sau đó hủy quay lại GridView, mọi thứ đều hoạt động tốt.

GIẢI PHÁP: Giải pháp của tôi là đặt chế độ mặc định của FormView thành "Chỉnh sửa". Lý thuyết của tôi là nếu chế độ mặc định FormView là "ReadOnly", khi tôi hủy từ chế độ Chỉnh sửa của FormView, lần tải trang tiếp theo, nó sẽ cố gắng áp dụng Chế độ xem của chế độ Chỉnh sửa sang chế độ ReadOnly (mặc định khi tải trang). Bằng cách đặt chế độ xem mặc định thành "Chỉnh sửa", Chế độ xem đã được lưu với chế độ Chỉnh sửa sẽ được tải lại vào chế độ Chỉnh sửa hiện tại mới (mặc định) sau khi tải trang.

Điều này tất cả xảy ra mặc dù ActiveView hiện tại của MultiView đang hiển thị lưới và không phải biểu mẫu.

tôi đã không có bất kỳ vấn đề ViewState kể từ khi chuyển sang chế độ mặc định của FormView để "Chỉnh sửa"

Hope this helps, và tôi hoan nghênh bất kỳ ý kiến.

Cảm ơn.

Harv Sather

0

Không thể tải ViewState này xảy ra chủ yếu khi sử dụng vài việc xây dựng trong các lệnh cho các điều khiển ASP dùng để thay đổi quan điểm với instace sau lưng hoặc sự kiện Async Postback

Ví dụ: Điều khiển như Gridview , Multiview, Formview, Listview.

Đối với tất cả các điều khiển trên các sự kiện lệnh như 'edit' (mà Convers chế độ chỉnh sửa) vào thời điểm này không có sự kiện 2 tồn tại như 1) 'onrowediting' 2) 'onrowedited' Note 2 tổ chức sự kiện does't tồn tại. nếu bạn đang cố gắng thêm điều khiển động tại thời điểm này 'Không tải được chế độ xem tuyến tính' xảy ra.

Giải pháp: Chúng ta cần phải sử dụng các lệnh như 'select' trong đó có cả hai sự kiện riêng biệt như 1) 'onselectedindexchanging' và 2) 'onselectedindexchanged'

Sử dụng 2 sự kiện thứ mà chúng ta có thể thêm các điều khiển và thiết lập css, tài sản .. động. mà sẽ không thông qua thất bại để tải lỗi ViewState. nhưng tương tự nếu chúng ta đang sử dụng nó trong sự kiện đầu tiên nó có thể ném lỗi.

Các vấn đề liên quan