object reference not set to instant of an object
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
Code: ( text )
1.
using System;
2.
using System.Data;
3.
using System.Configuration;
4.
using System.Collections;
5.
using System.Web;
6.
using System.Web.Security;
7.
using System.Web.UI;
8.
using System.Web.UI.WebControls;
9.
using System.Web.UI.WebControls.WebParts;
10.
using System.Web.UI.HtmlControls;
11.
using System.Data.SqlClient;
12.
using TimeEntrySystem;
13.
using TimeEntrySystem.BLL;
14.
15.
public partial class dailyreport : System.Web.UI.Page
16.
{
17.
private DataTable objDataTable;
18.
private Reports objReport;
19.
20.
protected void btn_show_report_Click(object sender, EventArgs e)
21.
{
22.
DateTime startingDate = Convert.ToDateTime(tb_daily_report_date.Text);
23.
24.
#region
25.
btn_daily_report_show.Enabled = false;
26.
DailyReport(startingDate);
27.
btn_daily_report_show.Enabled = true;
28.
#endregion
29.
}
30.
31.
public void DailyReport(DateTime startingDate)
32.
{
33.
objDataTable = objReport.ReturnDailyReport(startingDate);
34.
if (objDataTable == null)
35.
{
36.
lb_daily_report_error.Text = "There is some error in record reports.";
37.
}
38.
if (objDataTable.Rows.Count == 0)
39.
{
40.
lb_daily_report_error.Text = "No Record found.";
41.
objDataTable.Clear();
42.
return;
43.
}
44.
}
45.
46.
public DataTable ObjDataTable
47.
{
48.
get { return objDataTable; }
49.
}
50.
protected void Page_Load(object sender, EventArgs e)
51.
{
52.
if (!IsPostBack)
53.
{
54.
objDataTable = new DataTable("DailyReports");
55.
objReport = new Reports();
56.
57.
DateTime startingDate = DateTime.Now.Date;
58.
tb_daily_report_date.Text = startingDate.Date.ToShortDateString();
59.
DailyReport(startingDate);
60.
}
61.
lb_report_duration1.Text = "Daily Report";
62.
lb_report_duration2.Text = tb_daily_report_date.Text;
63.
64.
vld_range_daily_report_tb_start_date.MinimumValue = objReport.GetMinDate().ToShortDateString();
65.
vld_range_daily_report_tb_start_date.MaximumValue = DateTime.Now.ToShortDateString();
66.
67.
}
68.
protected void start_img_Click(object sender, ImageClickEventArgs e)
69.
{
70.
tb_daily_report_date.Text = cld_tb_daily_report_date.SelectedDate.Value.ToStri ng();
71.
}
72.
}
after post objReport and objTable loose its reference from their classes
so please any body help me about that problem thanks
|