May 30, 2012, 2:06 AM
[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":
Oliver
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]