[CLOSED] Null Reference Object Ajax

  1. #1

    [CLOSED] Null Reference Object Ajax

    Hello!

    I'm trying to make some calculations after select a product but I receive the message "System.NullReferenceException"

    Detail:
    [NullReferenceException: Referência de objeto não definida para uma instância de um objeto.]
    Ext.Net.Observable.FireAsyncEvent(String eventName, ParameterCollection extraParams) +181
    Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument) +1932
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +176
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

    Here my code, the problem occurs when I use DirectEvents to call the method "recalcularValores":

    <%@ Control Language="C#" %>
    <%@ Import Namespace="System.Linq" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Collections" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
    
        ModeloDataContext dcItem = new ModeloDataContext();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                //this.PedidoItemStore.DataSource = listarCadastro();
                //this.PedidoItemStore.DataBind();
            }
        }
    
        protected void recalcularValores(object sender, DirectEventArgs e)
        {
            this.dbVlrUnitario.Text = "2.5";
            if (this.dbVlrDesconto.Text != "" && this.dbVlrUnitario.Text != "") this.dbVlrCustoUnitario.Text = Convert.ToString(Convert.ToDouble(this.dbVlrUnitario.Text) - Convert.ToDouble(this.dbVlrDesconto.Text));
            if (this.dbVlrCustoUnitario.Text != "" && this.dbQtdPedido.Text != "") this.dbVlrTotalitem.Text = Convert.ToString(Convert.ToDouble(this.dbVlrCustoUnitario.Text) - Convert.ToDouble(this.dbQtdPedido.Text));
        }
    
    
        public void posicionarProduto()
        {
    
            var lista = from f in dcItem.Produtos
                        orderby f.cNmProduto
                        select new
                        {
                            f.nCdProduto,
                            f.cNmProduto
                        };
    
            this.StoreProduto.DataSource = lista;
            this.StoreProduto.DataBind();
        }
    
        public Store GridStore { get; set; }
    
        public void Show()
        {
            this.PedidoItemDetailsWindow.Show();
        }
    
        protected void SavePedidoItem(object sender, DirectEventArgs e)
        {
            //NorthwindDataContext db = new NorthwindDataContext();
            //int id = int.Parse(e.ExtraParams["id"]);
    
            //Employee empl = Employee.GetEmployee(id, db);
    
            ////Company
            //empl.FirstName = this.FirstName.Text;
            //empl.LastName = this.LastName.Text;
            //empl.Title = this.Title.Text;
    
            //if (!string.IsNullOrEmpty(this.ReportsTo.SelectedItem.Value))
            //{
            //    empl.ReportsTo = int.Parse(this.ReportsTo.SelectedItem.Value);
            //}
            //else
            //{
            //    empl.ReportsTo = null;
            //}
    
            //empl.HireDate = this.HireDate.SelectedDate;
            //empl.Extension = this.Extension.Text;
    
            ////Personal
            //empl.Address = this.Address.Text;
            //empl.City = this.City.Text;
            //empl.PostalCode = this.PostCode.Text;
            //empl.HomePhone = this.HomePhone.Text;
            //empl.TitleOfCourtesy = this.TitleCourt.Text;
            //empl.BirthDate = this.BirthDate.SelectedDate;
            //empl.Region = this.Region.Text;
            //empl.Country = this.Country.Text;
            //empl.Notes = this.Note.Text;
    
            //db.SubmitChanges();
    
            //var record = this.GridStore.GetById(id);        
    
            //this.EmployeeDetailsWindow.Hide();
            //CompanyInfoTab.UpdateRecord(record);
            //PersonalInfoTab.UpdateRecord(record);
            //record.Commit();
        }
    </script>
    <ext:Window ID="PedidoItemDetailsWindow" runat="server" Icon="BookEdit" Title="Item do Pedido"
        Width="500" Height="350" AutoShow="false" Modal="true" Hidden="true" Layout="Fit">
        <Items>
            <ext:FormPanel ID="DadosProdutoform" runat="server" Title="Dados do Produto" Icon="BookNext"
                DefaultAnchor="100%" BodyPadding="5" Frame="true">
                <Items>
                    <ext:TextField ID="dbCdItemPedido" runat="server" FieldLabel="Item Pedido" Name="dbCdItemPedido"
                        Width="200" Disabled="true" />
                    <ext:ComboBox ID="dbProdutoCodigo" runat="server" FieldLabel="Produto" Name="dbProdutoCodigo"
                        AllowBlank="false" DisplayField="cNmProduto" ValueField="nCdProduto" TypeAhead="true"
                        QueryMode="Local" ForceSelection="true" TriggerAction="Query" EmptyText="Selecione um produto..."
                        Width="450" SubmitValue="true">
                        <Store>
                            <ext:Store runat="server" ID="StoreProduto">
                                <Model>
                                    <ext:Model ID="Model1" runat="server" IDProperty="nCdProduto">
                                        <Fields>
                                            <ext:ModelField Name="nCdProduto" />
                                            <ext:ModelField Name="cNmProduto" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
                        <DirectEvents>
                            <Select OnEvent="recalcularValores" />
                        </DirectEvents>
                    </ext:ComboBox>
                    <ext:TextField ID="dbQtdPedido" runat="server" FieldLabel="Qtd Pedido" Disabled="false"
                        Name="dbQtdPedido" Width="200">
                    </ext:TextField>
                    <ext:TextField ID="dbVlrUnitario" runat="server" FieldLabel="Vlr Unitário" Name="dbVlrUnitario"
                        Width="200" Disabled="true">
                    </ext:TextField>
                    <ext:TextField ID="dbVlrDesconto" runat="server" FieldLabel="Vlr Desconto" Name="dbVlrDesconto"
                        Width="200">
                    </ext:TextField>
                    <ext:TextField ID="dbVlrCustoUnitario" runat="server" FieldLabel="Custo Unitário"
                        Name="dbVlrCustoUnitario" Width="200" Disabled="true" />
                    <ext:TextField ID="dbVlrTotalitem" runat="server" FieldLabel="Vlr Total Item" Name="dbVlrTotalitem"
                        Width="200" Disabled="true" />
                </Items>
            </ext:FormPanel>
        </Items>
        <Buttons>
            <ext:Button ID="SaveButton" runat="server" Text="Salvar" Icon="Disk">
                <DirectEvents>
                    <Click OnEvent="SavePedidoItem" Failure="Ext.MessageBox.alert('Gravação Falhou', 'Erro durante processo de gravação');">
                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{PedidoItemDetailsWindow}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="#{EmployeeID1}.getValue()" Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button ID="CancelButton" runat="server" Text="Cancelar" Icon="Cancel">
                <Listeners>
                    <Click Handler="this.up('window').hide();" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
    Thanks in advance,

    Oliver
    Last edited by Daniil; Jun 01, 2012 at 1:37 PM. Reason: [CLOSED]
  2. #2
    Please post a test case reproduces the issue
  3. #3
    Hi Vladimir,

    Here an example reproducing the problem.

    Thanks,

    Oliver

    File TesteCall.aspx:
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register src="~/Objetos/Views/Teste.ascx" tagname="WindowEditor" tagprefix="uc1" %>
    
    <script runat="server">
       
    
        protected void Page_Load(object sender, EventArgs e)
        {        
            this.WindowEditor1.Show();            
        }
    
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Ext.NET Teste Case</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
       
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
     
            
            <uc1:WindowEditor ID="WindowEditor1" runat="server" />
        </form>
    </body>
    </html>
    File Teste.ascx:

    <%@ Control Language="C#" %>
    <%--<%@ Import Namespace="Ext.Net.Examples.Northwind"%>--%>
    <%@ Import Namespace="System.Linq" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Collections" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
    
        public string tipoAcessoItem = "";
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                //Posicionar Registro
                //this.PedidoItemStore.DataSource = listarCadastro();
                //this.PedidoItemStore.DataBind();
            }
        }
    
        public void IncluirPedidoItem()
        {
        }
    
    
        protected void recalcularValores(object sender, DirectEventArgs e)
        {
            this.dbVlrUnitario.Text = "2.5";
            if (this.dbVlrDesconto.Text != "" && this.dbVlrUnitario.Text != "") this.dbVlrCustoUnitario.Text = Convert.ToString(Convert.ToDouble(this.dbVlrUnitario.Text) - Convert.ToDouble(this.dbVlrDesconto.Text));
            if (this.dbVlrCustoUnitario.Text != "" && this.dbQtdPedido.Text != "") this.dbVlrTotalitem.Text = Convert.ToString(Convert.ToDouble(this.dbVlrCustoUnitario.Text) - Convert.ToDouble(this.dbQtdPedido.Text));
        }
    
        public void PosicionarPedidoItem(Pedido objPedidoCabecalho, ItemPedido objItem, string _tipoAcessoItem)
        {
        }
    
        public void posicionarProduto()
        {
    
            return;        
        }
    
        public Store GridStore { get; set; }
    
        public void Show()
        {
            this.PedidoItemDetailsWindow.Show();
        }
    
        protected void SavePedidoItem(object sender, DirectEventArgs e)
        {
        }
    </script>
    <ext:Window ID="PedidoItemDetailsWindow" runat="server" Icon="BookEdit" Title="Item do Pedido"
        Width="500" Height="350" AutoShow="false" Modal="true" Hidden="true" Layout="Fit">
        <Items>
            <ext:FormPanel ID="DadosProdutoform" runat="server" Title="Dados do Produto" Icon="BookNext"
                DefaultAnchor="100%" BodyPadding="5" Frame="true">
                <Items>
                    <ext:TextField ID="dbCdItemPedido" runat="server" FieldLabel="Item Pedido" Name="dbCdItemPedido"
                        Width="200" Disabled="true" />
                    <ext:ComboBox ID="dbProdutoCodigo" runat="server" FieldLabel="Produto" Name="dbProdutoCodigo"
                        AllowBlank="false" TypeAhead="true"
                        QueryMode="Local" ForceSelection="true" TriggerAction="Query" EmptyText="Selecione um produto..."
                        Width="450" SubmitValue="true">
                            <Items>
                                <ext:ListItem Text="Produto 1" Value="1" />
                                <ext:ListItem Text="Produto 2" Value="2" />
                            </Items>
                        <DirectEvents>
                            <Select OnEvent="recalcularValores" />
                        </DirectEvents>
                    </ext:ComboBox>
                    <ext:TextField ID="dbQtdPedido" runat="server" FieldLabel="Qtd Pedido" Disabled="false"
                        Name="dbQtdPedido" Width="200">
                    </ext:TextField>
                    <ext:TextField ID="dbVlrUnitario" runat="server" FieldLabel="Vlr Unitário" Name="dbVlrUnitario"
                        Width="200" Disabled="true">
                    </ext:TextField>
                    <ext:TextField ID="dbVlrDesconto" runat="server" FieldLabel="Vlr Desconto" Name="dbVlrDesconto"
                        Width="200">
                    </ext:TextField>
                    <ext:TextField ID="dbVlrCustoUnitario" runat="server" FieldLabel="Custo Unitário"
                        Name="dbVlrCustoUnitario" Width="200" Disabled="true" />
                    <ext:TextField ID="dbVlrTotalitem" runat="server" FieldLabel="Vlr Total Item" Name="dbVlrTotalitem"
                        Width="200" Disabled="true" />
                </Items>
            </ext:FormPanel>
        </Items>
        <Buttons>
            <ext:Button ID="SaveButton" runat="server" Text="Salvar" Icon="Disk">
                <DirectEvents>
                    <Click OnEvent="SavePedidoItem" Failure="Ext.MessageBox.alert('Gravação Falhou', 'Erro durante processo de gravação');">
                        <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{PedidoItemDetailsWindow}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="#{EmployeeID1}.getValue()" Mode="Raw" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button ID="CancelButton" runat="server" Text="Cancelar" Icon="Cancel">
                <Listeners>
                    <Click Handler="this.up('window').hide();" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
  4. #4
    Hi,

    Please clarify what are the steps to reproduce the exception?

    When I select any items in the ComboBox, no error are throwing.

    When I click the "Salvar" button, it throws
    Ext.get("EmployeeID1") is null
    JS error due to
    <ext:Parameter Name="id" Value="#{EmployeeID1}.getValue()" Mode="Raw" />
    because there is no control with "EmployeeID1" ID in the user control.
  5. #5
    By the way, is the issue reproducible with the latest sources from SVN or NuGet?
  6. #6
    Quote Originally Posted by Daniil View Post
    Hi,

    Please clarify what are the steps to reproduce the exception?

    When I select any items in the ComboBox, no error are throwing.

    When I click the "Salvar" button, it throws
    Ext.get("EmployeeID1") is null
    JS error due to
    <ext:Parameter Name="id" Value="#{EmployeeID1}.getValue()" Mode="Raw" />
    because there is no control with "EmployeeID1" ID in the user control.
    Hi Daniil,

    The error are throwing when I select any item in Combobox, maybe can be a version problem.

    I´m using the beta version by nugget.

    Thanks
  7. #7
    There was the Ext.NET NuGet update this week. Please update and retest.
  8. #8
    Hi Daniil,

    After update the version works.

    Thanks,

    Oliver

Similar Threads

  1. ComboBox SelectedItem gets null reference error
    By zfreeman in forum 2.x Help
    Replies: 1
    Last Post: Jul 31, 2012, 7:40 PM
  2. Replies: 1
    Last Post: Jun 27, 2012, 9:19 PM
  3. Replies: 1
    Last Post: May 03, 2010, 2:32 PM
  4. Replies: 0
    Last Post: Jun 03, 2009, 4:18 AM
  5. [CLOSED] Ext Object Reference
    By Ben in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 08, 2009, 7:03 PM

Posting Permissions