Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2008, 01:35 PM
Registered User
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old September 5th, 2008, 02:01 PM
Registered User
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry i paste code of dailyreport.aspx and error show monthlyreport.aspx but both pages have same problem






Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set flashmanTom BOOK: Beginning VB.NET Databases 1 February 19th, 2008 06:29 AM
Object Reference not set to an instance of object srinivas_chakka ASP.NET 1.0 and 1.1 Professional 0 February 8th, 2006 11:56 AM
[NullReferenceException: Object reference not set creiche ASP.NET 1.0 and 1.1 Basics 3 September 23rd, 2003 08:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.