1
Answer

problem after postback object not set to instant

shahid

shahid

16y
3.7k
1
hi

i have a object to a user defined class which properly intialized from class when first form load, but after post back it loose reference and such error occured

[NullReferenceException: Object reference not set to an instance of an object.]
monthlyreport.GetReport() in c:\Time Entry System\WebTimeEntrySystem\monthlyreport.aspx.cs:10 0
monthlyreport.btn_show_report_Click(Object sender, EventArgs e) in c:\Time Entry System\WebTimeEntrySystem\monthlyreport.aspx.cs:94
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

My c# code is

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using TimeEntrySystem;
using TimeEntrySystem.BLL;

public partial class dailyreport : System.Web.UI.Page
{
private DataTable objDataTable;
private Reports objReport;

protected void btn_show_report_Click(object sender, EventArgs e)
{
DateTime startingDate = Convert.ToDateTime(tb_daily_report_date.Text);

#region
btn_daily_report_show.Enabled = false;
DailyReport(startingDate);
btn_daily_report_show.Enabled = true;
#endregion
}

public void DailyReport(DateTime startingDate)
{
objDataTable = objReport.ReturnDailyReport(startingDate);
if (objDataTable == null)
{
lb_daily_report_error.Text = "There is some error in record reports.";
}
if (objDataTable.Rows.Count == 0)
{
lb_daily_report_error.Text = "No Record found.";
objDataTable.Clear();
return;
}
}

public DataTable ObjDataTable
{
get { return objDataTable; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
objDataTable = new DataTable("DailyReports");
objReport = new Reports();

DateTime startingDate = DateTime.Now.Date;
tb_daily_report_date.Text = startingDate.Date.ToShortDateString();
DailyReport(startingDate);
}
lb_report_duration1.Text = "Daily Report";
lb_report_duration2.Text = tb_daily_report_date.Text;

vld_range_daily_report_tb_start_date.MinimumValue = objReport.GetMinDate().ToShortDateString();
vld_range_daily_report_tb_start_date.MaximumValue = DateTime.Now.ToShortDateString();

}
protected void start_img_Click(object sender, ImageClickEventArgs e)
{
tb_daily_report_date.Text = cld_tb_daily_report_date.SelectedDate.Value.ToStri ng();
}
}

after post objReport and objTable loose its reference from their classes

so please any body help me about that problem thanks
Answers (1)