2012-09-13 49 views
0

點擊我有後續aspx頁面錯誤,當我在一個按鈕

<asp:Content ID="Content2" ContentPlaceHolderID="contentConteudo" runat="server">   
    <table border="0" width="680" style="background-color:#f0f0f0" id="tabelaPrincipal" runat="server"> 
     <tr> 
      <td style="width: 180px !important;">    
       <asp:RadioButtonList ID="rbBuscas" runat="server"> 
        <asp:ListItem Selected="True">Novo Curso</asp:ListItem> 
        <asp:ListItem>Buscar Lista de Presença</asp:ListItem> 
       </asp:RadioButtonList>   
      </td> 
      <td> 
       Data: <br /> 
       <input id="DtBusca" type="text" />     
       <asp:Button id="btnSelecionarData" runat="server" Text="Buscar" /> 
      </td> 
     </tr> 
    </table> 


    <br /><br /> 
    <div id="infoGrid" runat="server"> 
     <cc1:GridView ID="grdImoveis" CssClass="StyleGrid" Width="100%" runat="server" ShowHeader="false" 
      AutoGenerateColumns="False" DataSourceID="dsGrid" BorderWidth="0px" GridLines="None" 
      AllowPaging="True" EnableModelValidation="True"> 
      <AlternatingRowStyle BackColor="White" CssClass="EstiloDalinhaAlternativaGrid" HorizontalAlign="Center" /> 
      <RowStyle CssClass="EstiloDalinhaGrid" HorizontalAlign="Center" /> 
      <Columns> 
       <asp:TemplateField HeaderText="Nome"> 
        <ItemTemplate> 
         <div class="<%# Eval("Usuario_Id").ToString() %>"> 
          <%# Eval("NomeCompleto").ToString() %> 
         </div> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:BoundField HeaderText="Cargo" DataField="DescricaoCargo1" /> 
       <asp:BoundField HeaderText="Data Cadastro" DataField="DataHora" /> 
       <asp:TemplateField ControlStyle-CssClass="acoes_lista_imovel" HeaderText="Curso"> 
        <ItemTemplate> 
         <div class="acoes_lista_imovel"> 
          <%# montaIcones(Eval("Usuario_Id").ToString())%> 
         </div> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField> 
        <ItemTemplate> 
         <div> 
          <%# montaIconesDocumentacao(Eval("Usuario_Id").ToString())%> 
         </div> 
        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
     </cc1:GridView> 
     <asp:SqlDataSource ID="dsGrid" runat="server"></asp:SqlDataSource> 
    </div> 
    <span id="printContrato" class="diasRelatorio btStep ui-button ui-widget ui-state-default ui-corner-all"></span> 


</asp:Content> 

當我在單擊出現的問題,我tryied把OnClick事件,但仍然發生了錯誤。

<asp:Button id="btnSelecionarData" runat="server" Text="Buscar" />

錯誤

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.

後面的代碼

public partial class ListaUsuarioProvisorio : System.Web.UI.Page 
    { 
     neticonn.Conexao c = new neticonn.Conexao(); 
     Utilidade.QuebraToken tk = new Utilidade.QuebraToken(); 
     public string icones = string.Empty; 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!IsPostBack) 
      { 
       this.CarregaLista(); 
      } 
     } 

     protected void CarregaLista() 
     { 
      string select = string.Empty; 
      select += "SELECT San_Credenciada.Apelido, San_Usuario.NomeCompleto, San_Usuario.Usuario_Id, San_Usuario.DescricaoCargo1, " 
       + "CONVERT(varchar, San_Usuario.DataHora, 103) AS DataHora " 
       + "FROM San_Usuario " 
       + "JOIN San_Credenciada " 
       + "ON San_Usuario.Credenciada_Id = San_Credenciada.Credenciada_Id " 
       + "WHERE San_Usuario.Provisorio = 1 " 
       + "AND San_Usuario.Excluido = 0 " 
       + "GROUP BY San_Credenciada.Apelido, San_Usuario.NomeCompleto, San_Usuario.Usuario_Id, " 
       + "San_Usuario.DescricaoCargo1, San_Usuario.DataHora " 
       + "ORDER BY San_Usuario.DataHora ASC "; 

      dsGrid.ConnectionString = c.Con; 
      dsGrid.SelectCommand = select; 
      dsGrid.Dispose(); 

      GridViewHelper helper = new GridViewHelper(this.grdImoveis); 
      helper.RegisterGroup("Apelido", true, true);    
      helper.GroupHeader += new GroupEvent(helper_GroupHeader); 
      helper.ApplyGroupSort(); 
     } 

     protected void CarregaLista(string data) 
     { 
      string select = string.Empty; 
      select += "SELECT San_Credenciada.Apelido, San_Usuario.NomeCompleto, San_Usuario.Usuario_Id, San_Usuario.DescricaoCargo1, " 
       + "CONVERT(varchar, San_Usuario.DataHora, 103) AS DataHora " 
       + "FROM San_Usuario " 
       + "JOIN San_Credenciada " 
       + "ON San_Usuario.Credenciada_Id = San_Credenciada.Credenciada_Id " 
       + "JOIN San_UsuarioCurso " 
       + "ON San_Usuario.Usuario_Id = San_UsuarioCurso.Usuario_Id " 
       + "WHERE San_Usuario.Provisorio = 1 " 
       + "AND San_Usuario.Excluido = 0 " 
       + "AND San_UsuarioCurso = " + data + " " 
       + "GROUP BY San_Credenciada.Apelido, San_Usuario.NomeCompleto, San_Usuario.Usuario_Id, " 
       + "San_Usuario.DescricaoCargo1, San_Usuario.DataHora " 
       + "ORDER BY San_Usuario.DataHora ASC "; 

      dsGrid.ConnectionString = c.Con; 
      dsGrid.SelectCommand = select; 
      dsGrid.Dispose(); 

      GridViewHelper helper = new GridViewHelper(this.grdImoveis); 
      helper.RegisterGroup("Apelido", true, true); 
      helper.GroupHeader += new GroupEvent(helper_GroupHeader); 
      helper.ApplyGroupSort(); 
     } 

     private void helper_GroupHeader(string groupName, object[] values, GridViewRow row) 
     { 
      string xCol = "#f56d01"; 
      string yCol = "#cbcbcb"; 
      Color c = System.Drawing.ColorTranslator.FromHtml(xCol); 
      Color c2 = System.Drawing.ColorTranslator.FromHtml(yCol); 

      if (groupName == "Apelido") 
      { 
       row.BackColor = c; 
       row.Cells[0].Text = "<div class='AgrupamentoPrincipal'>&nbsp;&nbsp;" + Maiscula(row.Cells[0].Text) + "</div>"; 
       row.Cells[0].Text += "</div><tr bgcolor=#e2dcd2 class=thGrid><th scope=col height='27'>&nbsp;Nome</th><th scope=col>Cargo</th><th>Data Cadastro</th><th scope=col>Curso Básico</th><th>Documentação Imobiliária</th></tr>";    
      } 
     } 

     protected string Maiscula(string texto) 
     { 
      texto = texto.ToUpper(); 
      return texto; 
     } 

     protected string montaIcones(string id) 
     { 
      icones = string.Empty;    
      int Credenciada = Convert.ToInt32(tk.CarregaToken(1, Request.Cookies["token"].Value)); 
      icones = "<img src='../tema/default/icon/icon-cinza/check.png' onclick=\"Visibilidade('" + id + "', '" + id + "', '" + Credenciada + "')\" style='cursor:pointer;margin: 4px;text-align:center;' ID='" + id + "' />"; 
      return icones; 
     } 

     protected string montaIconesDocumentacao(string id) 
     { 
      icones = string.Empty; 
      int Credenciada = Convert.ToInt32(tk.CarregaToken(1, Request.Cookies["token"].Value)); 
      icones = "<img src='../tema/default/icon/icon-cinza/documents.png' onclick=\"VisibilidadeDocumentacao('" + id + "', 'documentacao_" + id + "', '" + Credenciada + "')\" style='cursor:pointer;margin: 4px;text-align:center;' ID='documentacao_" + id + "' />"; 
      return icones; 
     } 

     public void btnSelecionarData_OnClick(object sender, EventArgs e) 
     { 
      if (this.rbBuscas.SelectedIndex == 1 && !this.DtBusca.Value.Equals(string.Empty)) 
      { 
       this.CarregaLista(this.DtBusca.Value); 
      } 
     } 
    } 
} 

有人能幫助我嗎?

+0

請出示'btnSelecionarData'按鈕的處理程序 – opewix

+0

當我嘗試把一個'OnClick'的錯誤仍然發生 –

回答

1

當您在後面的代碼中創建自定義控件時,通常會發生此問題。我想看看這篇文章,它進入深度有關問題的根源,以及如何當場檢查你的代碼對於這樣的問題:

http://blog.typps.com/2008/01/failed-to-load-viewstate-typical.html

+0

我的aspx頁面,從我的母版頁繼承,所以問題可以在我的母版頁? –

+0

是的,它可能在任何後臺運行的代碼中,包括母版頁,頁面和用戶控件。根據文章,您應該在條件內查找動態控制更改,特別是處理初始頁面負載與回發之間的差異。我將補充一點,這是ASP .net中更令人沮喪的錯誤之一,因爲它有時可能沒有警告地出現,因爲它涉及到條件,所以有時它不會一直髮生。 –

+0

這是一個很好的提示,謝謝。只是一個小小的觀察,我現在試着在我的頁面加載中加入一個'IsPostBack'。結果:當我的頁面加載時,我的'GridView'沒有被填充,但是如果我點擊我的按鈕,'GridView'被填充。我需要的是,當頁面被加載時,我的'GridView'必須被填充,當我點擊我的按鈕時,我需要再次填充我的'GridView',但有一些不同的參數,我通過,但在這個wy發生'viewstate'問題。 –

相關問題