PageRequestManagerServerErrorException对象引用未设置... ASP.net AJAX

时间:2015-02-27 18:27:17

标签: c# asp.net ajax

是否有人能够理解为什么我会收到此错误?

Uncaught Sys.WebForms.PageRequestManagerServerErrorException:Sys.WebForms.PageRequestManagerServerErrorException:对象引用未设置为对象的实例。

SOURCE:ScriptResource.axd

所以这就是......

首次点击时(首次访问网站后)我有一个按钮,但之后我总是收到错误。我尝试通过在Page_Load事件的第一行放置调试点来调试主题,但它甚至没有到达那里。

错误显示在那个由javascript构成的ScriptResources.axd文件之前,所以我试图调试它,但我真的不明白发生了什么,所以我找不到问题。

从我可以理解的,不知何故,当我第一次点击按钮时,我不能初始化一些控件我应该,但我只是想不出来。

按钮id = btnFiltra

HTML

<body>
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <script type="text/javascript">
        Sys.Application.add_load(onPageLoad);
    </script>
    <asp:Panel runat="server" ID="pHeader" CssClass="PVHeaderBackground">
        <img alt="Planview" src="Images/logo_planview.png" class="PVLogoBackImgleft"/>
        <div id="PTLogo" class="PTLogosRight">
            <img src="Images/logo_meo_preto.png" alt="Meo" style="vertical-align:middle; margin-top:auto; margin-bottom:auto"/>
            <img src="Images/Ptlogo.jpg" alt="PT" style="height:50px; width:auto; margin-left:10px; vertical-align:middle;margin-top:auto; margin-bottom:auto"/>
        </div>
    </asp:Panel>
    <asp:UpdatePanel ID="upBody" runat="server" UpdateMode="Conditional" >
        <ContentTemplate>
        <asp:Panel runat="server" ID="pOpcoesGlobais" >
            <asp:Button ID="btnExtrair" runat="server" OnClientClick="umProjetoApenas()" OnClick="btnExtrair_OnClick" Text="Extrair Dados"/>
            <asp:Button ID="btnAtualizar" runat="server" OnClientClick="umProjetoApenas()" OnClick="btnAtualizar_OnClick" Text="Atualizar Dados"/>
        </asp:Panel>
        <asp:Panel runat="server" ID="pTarefaOkFaturar" Visible="true" style="display:none;" Width="100%" Height="100%" >
            <div style="width:100%; height:10%">
                <b>Ao confirmar que a tarefa pode ser faturada, todas as parcelas sem documento passarão a ser faturadas de forma automática.</b>
            </div>
            <div style="width:100%;">
                <asp:GridView runat="server" ID="gvCheckParcelas" CssClass="PVPortlet"></asp:GridView>
            </div>
            <div style="width:100%;position: absolute;bottom: 10px;">
                <asp:Button ID="btnOkFaturarCancelar" runat="server" Text="Cancelar" OnClick="btnOkFaturarCancelar_OnClick" style="float:left;margin-left: 10px;"/>
                <asp:Button ID="btnOkFaturarOk" runat="server" Text="Concordo" OnClick="btnOkFaturarOk_OnClick" style="float:right;margin-right: 10px;" />
            </div>
        </asp:Panel>
        <asp:Panel runat="server" ID="pBody">
            <asp:UpdatePanel ID="upFiltros" runat="server">
                <ContentTemplate>
                    <asp:Label ID="lCliente" runat="server" Text="Cliente"/>               
                    <asp:TextBox ID="txbCliente" runat="server"/>
                    <asp:PopupControlExtender ID="txbCliente_PopupControlExtender" runat="server" Enabled="True" ExtenderControlID="" TargetControlID="txbCliente" 
                        PopupControlID="pPopUpCliente" Position="Bottom" >
                    </asp:PopupControlExtender>
                    <asp:Panel ID="pPopUpCliente" runat="server" Height="116px" BorderStyle="Solid" BorderWidth="2px" Direction="LeftToRight" ScrollBars="Auto" BackColor="#CCCCCC" Style="display: none" >
                        <asp:CheckBoxList ID="cblCliente" runat="server" DataTextField="DESCRICAO" onChange="uncheckOnTodos(this)" DataValueField="ID" AutoPostBack="False" AppendDataBoundItems="True">
                             <asp:ListItem Text="Todos" Value="all" Selected="False"></asp:ListItem>
                        </asp:CheckBoxList>
                    </asp:Panel>
                    <asp:Label ID="lPedido" runat="server" Text="Pedido"/>
                    <asp:TextBox ID="txbPedido" runat="server"/>
                    <asp:PopupControlExtender ID="txbPedido_PopupControlExtender" runat="server"
                        Enabled="True" ExtenderControlID="" TargetControlID="txbPedido" 
                        PopupControlID="pPopUpPedido" Position="Bottom" >
                    </asp:PopupControlExtender>
                    <asp:Panel ID="pPopUpPedido" runat="server" Height="116px" 
                         BorderStyle="Solid" BorderWidth="2px" Direction="LeftToRight"
                         ScrollBars="Auto" BackColor="#CCCCCC" Style="display: none" >
                        <asp:CheckBoxList ID="cblPedido" runat="server" 
                             DataTextField="DESCRICAO" onChange="uncheckOnTodos(this)"
                             DataValueField="ID" AutoPostBack="False" AppendDataBoundItems="True">
                             <asp:ListItem Text="Todos" Value="all" Selected="False"></asp:ListItem>
                        </asp:CheckBoxList>
                    </asp:Panel>
                    <asp:Label ID="lProjeto" runat="server" Text="Projeto"/>
                    <asp:TextBox ID="txbProjeto" runat="server"/>

                    <asp:PopupControlExtender ID="txbProjeto_PopupControlExtender" runat="server"
                        Enabled="True" ExtenderControlID="" TargetControlID="txbProjeto" 
                        PopupControlID="pPopUpProjeto" Position="Bottom" >
                    </asp:PopupControlExtender>
                    <asp:Panel ID="pPopUpProjeto" runat="server" Height="116px" 
                         BorderStyle="Solid" BorderWidth="2px" Direction="LeftToRight" ScrollBars="Auto" BackColor="#CCCCCC" Style="display: none" >
                        <asp:CheckBoxList ID="cblProjeto" runat="server" 
                             DataTextField="DESCRICAO" onChange="uncheckOnTodos(this)"
                             DataValueField="ID" AutoPostBack="False" AppendDataBoundItems="True">
                             <asp:ListItem Text="Todos" Value="all" Selected="False"></asp:ListItem>
                        </asp:CheckBoxList>
                    </asp:Panel>
                    <asp:Button runat="server" ID="btnFiltra" Text="Pesquisar" 
                        onclick="btnFiltra_Click"/>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:UpdateProgress ID="uprgTarefas" runat="server" AssociatedUpdatePanelID="upTarefas" DisplayAfter="2000" >
                <ProgressTemplate>Loading...</ProgressTemplate>
            </asp:UpdateProgress>
            <asp:UpdatePanel ID="upTarefas" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnFiltra" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="btnAtualizar" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="btnExtrair" EventName="Click" />
                </Triggers>
                <ContentTemplate>
                    <div id="dTabelaTarefaHeader" class="PVPortletHeader">
                        <div id="dTabelaTarefasOpcoes" class="PVPortletHeaderOpcoes"></div>
                        <b>Tarefas Faturação</b>
                    </div>
                    <asp:Panel runat="server" ID="pgvTarefasEmpty" Visible="false">
                        <table class="PVPortlet">
                             <tbody>
                                <tr>
                                    <th></th>
                                    <th>ID</th>
                                    <th>Projeto</th>
                                    <th>Tarefa</th>
                                    <th>Cliente</th>
                                    <th>Pedido</th>
                                    <th>Inicio</th>
                                    <th>Fim</th>
                                    <th>Faturar?</th>
                                    <th>Planeado</th>
                                    <th>Remanescente</th>
                                    <th>Faturado</th>
                                    <th>Entidade</th>
                                </tr>
                                <tr>
                                    <td colspan="13">Sem dados...</td>
                                </tr>
                             </tbody>                   
                        </table>
                    </asp:Panel>
                    <asp:GridView ID="gvTarefas" runat="server" AutoGenerateSelectButton="true" 
                        AutoGenerateColumns="false" CssClass="PVPortlet" SelectedRowStyle-CssClass="PVPortletSelectedRow"
                        onselectedindexchanged="gvTarefas_SelectedIndexChanged" DataKeyNames="ID"
                        OnRowCreated="gvTarefas_OnRowCreated">
                        <columns>
                            <asp:BoundField DataField="ID" HtmlEncode="false" HeaderText="ID" />
                            <asp:BoundField DataField="Projeto" HtmlEncode="false" HeaderText="Projeto" />
                            <asp:BoundField DataField="Tarefa" HtmlEncode="false" HeaderText="Tarefa" />
                            <asp:BoundField DataField="Cliente" HtmlEncode="false" HeaderText="Cliente" />
                            <asp:BoundField DataField="Pedido" HtmlEncode="false" HeaderText="Pedido" />
                            <asp:BoundField DataField="DataInicio" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Inicio" />
                            <asp:BoundField DataField="DataFim" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Fim" />
                            <asp:TemplateField HeaderText="Faturar?">
                                <ItemTemplate>
                                    <asp:CheckBox runat="server" ID="cbFaturar" Checked='<%# Eval("ProntoAFaturar") %>' AutoPostBack="true" OnCheckedChanged="cb_OnCheckedChanged"/>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Planeado" HeaderText="Planeado" />
                            <asp:BoundField DataField="Remanescente" HeaderText="Remanescente" />
                            <asp:BoundField DataField="Faturado" HeaderText="Faturado" />
                            <utl:CompositeBoundField HeaderText="Entidade" DataField="EntidadeResponsavel.Descricao" />
                        </columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
            <br />
            <asp:UpdateProgress ID="uprgParcelas" runat="server" 
                AssociatedUpdatePanelID="upParcelas" DisplayAfter="2000">
                <ProgressTemplate>Loading...</ProgressTemplate>
            </asp:UpdateProgress>
            <asp:UpdatePanel ID="upParcelas" runat="server" UpdateMode="Conditional">
                <Triggers>
                    <asp:asyncpostbacktrigger controlid="gvTarefas" 
                        EventName="SelectedIndexChanged" />
                    <asp:asyncpostbacktrigger controlid="gvParcelas" EventName="RowEditing" />
                </Triggers>
                <ContentTemplate>
                    <div ID="dTabelaParcelasHeader" class="PVPortletHeader">
                        <b>Parcelas Faturação</b>
                    </div>
                    <asp:Panel ID="pgvParcelasEmpty" runat="server" Visible="false">
                        <table class="PVPortlet">
                            <tbody>
                                <tr>
                                    <th></th>
                                    <th>ID</th>
                                    <th>Auto</th>
                                    <th>DataEnvio</th>
                                    <th>Descrição</th>
                                    <th>Valor</th>
                                </tr>
                                <tr>
                                    <td colspan="6">Sem dados...</td>
                                </tr>
                            </tbody>
                        </table>
                    </asp:Panel>
                    <asp:GridView ID="gvParcelas" runat="server"   AutoGenerateColumns="false" AutoGenerateDeleteButton="true"  AutoGenerateEditButton="true"AutoGenerateSelectButton="true"  CssClass="PVPortlet" DataKeyNames="ID"  OnRowCancelingEdit="gvParcelas_OnRowCancelingEdit" 
OnRowCommand="gvParcelas_OnRowCommand"  OnRowCreated="gvParcelas_OnRowCreated" OnRowDeleting="gvParcelas_OnRowDeleting"  OnRowEditing="gvParcelas_RowEditing" OnRowUpdating="gvParcelas_OnRowUpdating"  Visible="false" SelectedRowStyle-CssClass="PVPortletSelectedRow"
OnSelectedIndexChanged="obterDocumento_OnSeacrh" ShowFooter="True">
                        <Columns>
                            <asp:TemplateField HeaderText="ID">
                                <EditItemTemplate>
                                    <asp:Label ID="lIDParcela" runat="server" Text='<%# Eval("ID") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lIDParcela" runat="server" Text='<%# Eval("ID") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Button ID="btnParcelaNovo" runat="server" CommandName="Insert" Text="Novo" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Auto">
                                <EditItemTemplate>
                                    <asp:CheckBox ID="cbAuto" runat="server" Checked='<%# Eval("Auto") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:CheckBox ID="cbAuto" runat="server" Checked='<%# Eval("Auto") %>' Enabled="false"/>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:CheckBox ID="cbAuto" runat="server" Checked="true" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="DataEnvio">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txbDataEnvio" runat="server" Text='<%# Eval("DataEnvio","{0:dd-MM-yyyy}") %>' />
                                    <asp:CalendarExtender ID="txbDataEnvio_CalendarExtender" runat="server" 
                                        DefaultView="Months" Enabled="True" Format="MM-yyyy" PopupPosition="BottomLeft" 
                                        TargetControlID="txbDataEnvio">
                                    </asp:CalendarExtender>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lDataEnvio" runat="server" 
                                        Text='<%# Eval("DataEnvio","{0:dd-MM-yyyy}") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txbDataEnvio" runat="server" Text="" />
                                    <asp:CalendarExtender ID="txbDataEnvio_CalendarExtender" runat="server" 
                                        DefaultView="Months" Enabled="True" Format="MM-yyyy" PopupPosition="BottomLeft" 
                                        TargetControlID="txbDataEnvio">
                                    </asp:CalendarExtender>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Descrição">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txbDescricao" runat="server" Text='<%# Eval("Descricao") %>' />
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lDescricao" runat="server" Text='<%# Eval("Descricao") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txbDescricao" runat="server" Text="" />
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Valor">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txbValor" runat="server" Text='<%# Eval("Valor") %>' />
                                    <asp:FilteredTextBoxExtender ID="txbValor_FilteredTextBoxExtender" runat="server" FilterType="Custom" TargetControlID="txbValor" ValidChars="0123456789,">
                                    </asp:FilteredTextBoxExtender>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lValor" runat="server" Text='<%# Eval("Valor") %>' />
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox ID="txbValor" runat="server" Text="" />
                                    <asp:FilteredTextBoxExtender ID="txbValor_FilteredTextBoxExtender" 
                                        runat="server" FilterType="Numbers" TargetControlID="txbValor">
                                    </asp:FilteredTextBoxExtender>
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>

            <asp:UpdateProgress ID="uprgDocumentos" runat="server" 
                AssociatedUpdatePanelID="upDocumentos" DisplayAfter="2000">
                <ProgressTemplate>Loading...</ProgressTemplate>
            </asp:UpdateProgress>
            <asp:UpdatePanel ID="upDocumentos" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <div ID="dTabelaDocumentosHeader" class="PVPortletHeader">
                        <div ID="dTabelaDocumentosOpcoes" class="PVPortletHeaderOpcoes">
                            <asp:Label ID="lDocInicio" runat="server" Text="Inicio" style="float:left;"></asp:Label>
                            <asp:TextBox ID="txbInicio" runat="server" style="float:left;"></asp:TextBox>
                            <asp:CalendarExtender ID="txbInicio_CalendarExtender" runat="server" Enabled="True" Format="MM-yyyy" TargetControlID="txbInicio">
                            </asp:CalendarExtender>
                            <asp:Label ID="lDocFim" runat="server" Text="Fim" style="float:left;"></asp:Label>
                            <asp:TextBox ID="txbFim" runat="server" style="float:left;"></asp:TextBox>
                            <asp:CalendarExtender ID="txbFim_CalendarExtender" runat="server" Enabled="True" Format="MM-yyyy" TargetControlID="txbFim">
                            </asp:CalendarExtender>
                            <asp:Button ID="btnDocFiltro" runat="server" Text="Pesquisar" style="float:left;" OnClick="obterDocumento_OnSeacrh"/>
                        </div>
                        <b>Documentos Faturação</b>
                        <asp:Button ID="btnNovoDocumento" runat="server" OnClientClick="abrirDocumento(0);" Text="Novo" style="float:right;"/>
                    </div>
                    <asp:Panel ID="pgvDocumentosEmpty" runat="server" Visible="false">
                        <table class="PVPortlet">
                            <tbody>
                                <tr>
                                    <th></th>
                                    <th>ID</th>
                                    <th>Fatura</th>
                                    <th>Enviado</th>
                                    <th>Estado</th>
                                    <th>Tipo</th>
                                    <th>Descrição</th>
                                    <th>Valor</th>
                                </tr>
                                <tr>
                                    <td colspan="8">Sem dados...</td>
                                </tr>
                            </tbody>
                        </table>
                    </asp:Panel>
                    <asp:GridView ID="gvDocumentos" runat="server" AutoGenerateColumns="false" AutoGenerateDeleteButton="false" AutoGenerateEditButton="false" AutoGenerateSelectButton="false" CssClass="PVPortlet">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:LinkButton Text="Abrir" runat="server" ID="lbtnAbrirDoc" OnClientClick='<%#"abrirDocumento(" + Eval("ID") + ");"%>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="ID" HeaderText="ID" HtmlEncode="false" />
                            <asp:BoundField DataField="NFATURA" HeaderText="Fatura" HtmlEncode="false" />
                            <asp:BoundField DataField="EnviadoA" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Enviado" HtmlEncode="false" />
                            <utl:CompositeBoundField DataField="Estado.Descricao" HeaderText="Estado" HtmlEncode="false" />
                            <utl:CompositeBoundField DataField="Tipo.Descricao" HeaderText="Tipo" HtmlEncode="false" />
                            <asp:TemplateField HeaderText="Descrição">
                                <ItemTemplate>
                                    <asp:Label ID="lCabecalho" runat="server" Text='<%#Eval("Cabecalho").ToString().Cut(30,true)+"-"+Eval("Periodo")%>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Valor" HeaderText="Valor" HtmlEncode="false" />
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>    
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

服务器SIde

 protected void Page_Load(object sender, EventArgs e)
            {
                userName = HttpContext.Current.User.Identity.Name.ToString().ToUpper();
                sessionID = Session.SessionID;

                if (!IsPostBack)
                {
                    Session["USER_" + sessionID] = userName;
                    Session["TAREFAS_INV_" + sessionID] = null;
                    Session["PARCELAS_"+sessionID] = null;
                    Session["DOCUMENTOS_"+sessionID] = null;

                    carregaDadosFiltros();

                    string idPrj = null;
                    obtemParametrosEntrada(ref idPrj);

                    pgvDocumentosEmpty.Visible = true;
                    pgvParcelasEmpty.Visible = true;
                    pgvTarefasEmpty.Visible = true;
                    gvDocumentos.Visible = false;
                    gvParcelas.Visible = false;
                    gvTarefas.Visible = false;

                    if (!string.IsNullOrEmpty(idPrj))
                    {
                        bool filtra = true;
                        if (cblProjeto.Items.FindByValue(idPrj) != null)
                        {
                            cblProjeto.SelectedValue = idPrj;
                        }
                        else
                        {
                            string nome = InvDataAccess.obterNomeProjeto(idPrj);
                            if(!string.IsNullOrEmpty(nome))
                            {
                                ListItem prj = new ListItem(nome, idPrj, true);
                                cblProjeto.Items.Add(prj);
                                cblProjeto.SelectedValue = prj.Value;
                            }
                            else
                                filtra = false;
                        }
                        cblCliente.SelectedValue = "all";
                        cblPedido.SelectedValue = "all";
                        if(filtra) btnFiltra_Click(null, null);
                    }
                }
                else
                {
                    userName = Session["USER_" + sessionID] as string;
                    DateTime inicio = DateTime.MinValue, fim = DateTime.MaxValue;
                    if (!DateTime.TryParseExact(txbInicio.Text, txbInicio_CalendarExtender.Format, null, System.Globalization.DateTimeStyles.None, out inicio))
                        txbInicio_CalendarExtender.SelectedDate = DateTime.MinValue;
                    if (!DateTime.TryParseExact(txbFim.Text, txbFim_CalendarExtender.Format, null, System.Globalization.DateTimeStyles.None, out fim))
                        txbFim_CalendarExtender.SelectedDate = DateTime.MaxValue;
                    if (Session["TAREFAS_INV_"+sessionID] != null)
                        tarefas = (Dictionary<int, InvTarefas>)Session["TAREFAS_INV_"+sessionID];

                    if (Session["PARCELAS_"+sessionID] != null)
                    {
                        parcelas = (Dictionary<int, InvParcelaTarefa>)Session["PARCELAS_"+sessionID];
                        gvParcelas.DataSource = parcelas.Values.ToList();
                    }

                    if (Session["DOCUMENTOS_"+sessionID] != null)
                    {
                        documentos = (Dictionary<int, InvDocumento>)Session["DOCUMENTOS_"+sessionID];
                        gvDocumentos.DataSource = documentos.Values.ToList();
                    }

                }
            }

protected void btnFiltra_Click(object sender, EventArgs e)
        {
            tarefas.Clear();
            List<string> idCliente, idPedido, idProjeto;
            DateTime inicio, fim;
            idCliente = cblCliente.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList();
            idPedido = cblPedido.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList();
            idProjeto = cblProjeto.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToList();
            inicio = DateTime.MinValue;
            fim = DateTime.MaxValue;
            List<InvTarefas> tars = InvTarefas.getInvTarefas(new List<string>{"all"}, idCliente, idPedido, idProjeto, inicio, fim);
            if (tars != null && tars.Count > 0)
            {
                foreach (InvTarefas tar in tars)
                {
                    tarefas.Add(tar.ID, tar);
                }
                this.Session["TAREFAS_INV_"+sessionID] = tarefas;
                gvTarefas.DataSource = tarefas.Values.ToList();
                gvTarefas.DataBind();
                pgvTarefasEmpty.Visible = false;
                gvTarefas.Visible = true;
            }
            else
            {
                this.Session["TAREFAS_INV_"+sessionID] = null;

                pgvTarefasEmpty.Visible = true;
                gvTarefas.Visible = false;
            }
        }

1 个答案:

答案 0 :(得分:4)

在一位同事的帮助下,我们发现gvTarefas_OnRowCreated事件在Page_load之前被触发,而且里面的代码是trowing null异常。

我还被建议将我的事件更改为OnRowDataBound。  另外,对于那些不知道你可以设置的人(当遇到麻烦,否则会加载很多)VS停止在抛出异常的行上调试 - &gt;异常 - &gt;抛出公共语言运行时例外。如果我知道这一点,我可能马上就解决了。

现在,关于Page_Load之前的奇怪的OnRowCreated,我仍然无法理解,但有些东西告诉我这是因为我的UpdatePanel upBody捕获了大部分页面,其更新模式是Always(是默认值)。 / p>

最后,我正在使用我的OnRowCreated代码

protected void gvTarefas_OnRowCreated(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            InvTarefas tar = e.Row.DataItem as InvTarefas;
            if (tar.EntidadeResponsavel != InvEntidadeResponsavel.PV_PROPRIO)
            {
                e.Row.Enabled = false;
                e.Row.CssClass = "PVPortlet_DisabledRoW";
            }
        }
    }