PDA

View Full Version : [CLOSED] Null Reference Object Ajax



Oliver
May 30, 2012, 2:06 AM
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.dbVlrUnitar io.Text) - Convert.ToDouble(this.dbVlrDesconto.Text));
if (this.dbVlrCustoUnitario.Text != "" && this.dbQtdPedido.Text != "") this.dbVlrTotalitem.Text = Convert.ToString(Convert.ToDouble(this.dbVlrCustoU nitario.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

Vladimir
May 30, 2012, 9:38 AM
Please post a test case reproduces the issue

Oliver
May 30, 2012, 6:31 PM
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.dbVlrUnitar io.Text) - Convert.ToDouble(this.dbVlrDesconto.Text));
if (this.dbVlrCustoUnitario.Text != "" && this.dbQtdPedido.Text != "") this.dbVlrTotalitem.Text = Convert.ToString(Convert.ToDouble(this.dbVlrCustoU nitario.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>

Daniil
May 31, 2012, 2:03 PM
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.

Daniil
May 31, 2012, 3:03 PM
By the way, is the issue reproducible with the latest sources from SVN or NuGet?

Oliver
May 31, 2012, 4:09 PM
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

Daniil
May 31, 2012, 6:59 PM
There was the Ext.NET NuGet update this week. Please update and retest.

Oliver
Jun 01, 2012, 1:18 PM
Hi Daniil,

After update the version works.

Thanks,

Oliver