2014-09-10 66 views
2

自舉模式是使用遠程gridview的pageindexchange錯誤:狀態信息是用於當前頁無效,可能損壞(替代的解決方案需要)

<a data-toggle="modal" data-target="#modal-panel" href="AdminUserMaintenance.aspx?id=<%# Eval("ProviderUserKey")%>" title="Edit" class="button-icons"><span class="glyphicon glyphicon-pencil"></span></a> 

迄今可能的是,誤差發生生成因爲__viewstate是變化因當pageindex發生變化時,如果我將gridview從bootstrap移動到一個新頁面,GridView分頁工作正常,如果在boostrap模式中,第一次單擊任何分頁後,第二次分頁會出現錯誤,有沒有其他方法可以做到這一點?錯誤

System.Web.HttpException(0X80004005)的

部分:國家信息是這個頁面無效,可能已損壞。 ---> System.Web.UI.ViewStateException:無效的視圖狀態。

enter image description here

代碼隱藏

Protected Sub gvAdminUser_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) 
    gvAdminUser.PageIndex = e.NewPageIndex 
    bindDataGrid() 
End Sub 

Private Sub bindDataGrid() 
    gvAdminUser.PageSize = _iMaximumRows 
    Dim oUser As MembershipUser = Membership.GetUser(UserID) 
    gvAdminUser.DataSource = Roles.GetAllRoles 
    gvAdminUser.DataBind() 
End Sub 

部分引導表

<asp:UpdatePanel ID="pnlUpdate" runat="server"> 
        <ContentTemplate> 
         <asp:GridView ID="gvAdminUser" runat="server" AutoGenerateColumns="false" 
          AllowPaging="true" EmptyDataText="No Data Found" BorderStyle="None"OnPageIndexChanging="gvAdminUser_PageIndexChanging"> 
          <PagerSettings Mode="Numeric" Position="TopAndBottom" /> 
          <Columns> 
           <asp:TemplateField HeaderText="Role" HeaderStyle-Width="40%" ItemStyle-HorizontalAlign="Left"> 
            <ItemTemplate> 
             <asp:Label runat="server" ID="RoleNameLabel" Text='<%# Container.DataItem %>' /> 
            </ItemTemplate> 
           </asp:TemplateField> 
          </Columns> 
         </asp:GridView> 
        </ContentTemplate> 
       </asp:UpdatePanel> 

參考到目前爲止

ASP.NET Error:The state information is invalid for this page and might be corrupted

http://blog.syedgakbar.com/2007/11/one-possible-reason-for-the-state-information-is-invalid-for-this-page-exception/

The state information is invalid for this page and might be corrupted. (Only in IE)

http://social.msdn.microsoft.com/Forums/vstudio/en-US/cc8b2fe2-ede4-4c95-b1a9-ed9002e6a0b7/the-state-information-is-invalid-for-this-page-and-might-be-corrupted?forum=netfxbcl

回答

0

第一次發現 這裏的問題是asp.net視圖狀態的問題,其中兩個形式將創建它自己的__viewstate,和ASP。網罩住認爲最頂端的形式是孩子,異常擊中時,在子窗體點擊分頁

<form id="parent"> 
... 
</form> 
<modal id="child"> 
<form></form> 
</modal> 

第二發現 我嘗試移動子窗體在底部的頂部和家長的形式,它的工作好了,也不例外命中,一切都正常工作,但父窗體將重定向到子頁面,而不與任何按鈕點擊事件,這是沮喪frustratio的幾日之後

<modal id="child"> 
<form></form> 
</modal> 
<form id="parent"> 
... 
</form> 

最終解決 任何風格N,我已經決定更改代碼,並改寫一個新的,可替代的方式使用iframe來顯示模式彈出,多數民衆贊成在另一種方式到目前爲止,我能找到的,它工作得非常好

鏈接

<a href="#" data-target="AdminUserMaintenance.aspx?id=<%# Eval("ProviderUserKey")%>" class="button-icons boot-frame"><span class="glyphicon glyphicon-pencil"></span></a> 

腳本

function ShowBootstrapModal(destLink) { 

    var modal = "<div class=\"modal fade\" id=\"iframeModal\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">" 
    modal = modal + "<div class=\"modal-dialog modal-lg\">"; 
    modal = modal + "<div class=\"modal-content\">"; 
    modal = modal + "<iframe src='" + destLink + "' frameborder='0' scrolling='no' seamless='seamless' allowTransparency='true' width='900px' height='0'></iframe>"; 
    modal = modal + "</div>"; 
    modal = modal + "</div>"; 
    modal = modal + "</div>"; 

    var $modal = $(modal); 
    $modal.append('body'); 
    $modal.modal({ 
     backdrop: 'static' 
    }); 

    $('body').addClass('modal-open'); 
    $modal.modal("show"); 
} 

$('.boot-frame').click(function (e) { 
    e.preventDefault(); 
    var $this = $(this); 
    ShowBootstrapModal($this.data("target")); 
}); 

和兒童模式裏面,我添加了一個代碼,以便IFRAME將擴大由內容大小的高度內,更改按鈕克羅SE

$(function() { 
      Sys.Application.add_load(ParentScript); 
     }); 

     function ParentScript() { 
      var $iframe = $('iframe', window.parent.document); 
      var $child = $iframe.contents().find('body .modal-body').children().height(); 
      $iframe.animate({ 
       height: $child + 160 
      }, { 
       queue: false, 
       duration: 500 
      }); 

      $('.frame-close').click(function() { 
       parent.updatePanel(); //call parent script to do refresh 
       var $parent = $(window.parent.document).contents("html"); 
       var $backdrop = $parent.find('.modal-backdrop'); 

       if ($backdrop.length > 1) { 
        $backdrop.slice(1).remove(); 
       } else { 
        $backdrop.remove(); 
       } 

       $parent.find('body').removeClass("modal-open"); 
       $parent.find('#iframeModal').remove(); 

      }); 
     } 

我共享出來的想法希望有人在那裏面臨着同樣的問題終於可以解決這一問題

1

只是猜測,

所以你提到的modal is generated using remote,這可能是你有無效的視圖狀態的原因。在頁面和模式上嘗試view source以查看是否在它們兩個上都生成了viewstate。

它看起來像這樣

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="SOMESTUFFHERE" /> 

如果你有兩個視圖狀態,儘量消除對使用JavaScript的模式彈出視圖狀態,如果開不工作,嘗試從服務器響應中刪除視圖狀態(在一個生成模式)

+0

什麼ü說是正確的,我嘗試使用jQuery來刪除它,但你猜asp.net已經在代碼後面的某個地方改變了viewstate,所以使用jquery刪除它將不起作用 – Se0ng11 2014-09-24 02:01:29

+0

我明白了。看來你已經解決了這個問題,否則,你可以直接從服務器的響應中刪除視圖狀態,然後到達瀏覽器。 – Andy 2014-09-24 03:37:30

相關問題