Connecting Tech Pros Worldwide Forums | Help | Site Map

ServerError:Object reference not set to an instance of an object.

Newbie
 
Join Date: Oct 2008
Posts: 7
#1: Nov 20 '08
Hi,

Im working on migration of one proj from .Net1.1 to2.0 in that some pages are unble to run;

on Debug i havent obeserved ani error at any line but in IE .getting this error

ServerError:Object reference not set to an instance of an object.

Expand|Select|Wrap|Line Numbers
  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.  
  12. /// <summary>
  13. /// Summary description for DCA_Reassign.
  14. /// </summary>
  15. public partial class Presentation_DCAdmin_DCA_Reassign : System.Web.UI.Page
  16. {
  17.  
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         Response.Cache.SetCacheability(HttpCacheability.NoCache);
  21.         CommonUI.CheckUser();
  22.         CommonUI.FillHeader(litHeader, "Diagnostic Center Admin");
  23.         btnView.Attributes.Add("onclick", "return validate();");
  24.         Session["pid"] = "1";
  25.         if (!IsPostBack)
  26.         {
  27.             Session["pid"] = "1";
  28.             DC_Admin objDCAdmin = new DC_Admin(Session["UserId"].ToString());
  29.             objDCAdmin.InsertUsageCount("P", Convert.ToInt32(Session["pid"].ToString()));
  30.             tblNoData.Visible = false;
  31.             tblDetails.Visible = false;
  32.             FillCountryList();
  33.             Response.Write("I am wrkin");
  34.           //  ddlLocation.Items.Insert(0, new ListItem("--Select--", "0"));
  35.           //  ddlDiagnosticCenter.Items.Insert(0, new ListItem("--Select--", "0"));
  36.         }
  37.         // Put user code to initialize the page here
  38.  
  39.     }
  40.  
  41.     private void FillCountryList()
  42.     {
  43.         try
  44.         {
  45.             DC_Admin objDCAdmin = new DC_Admin(Session["UserId"].ToString());
  46.             DataSet dsDetails = objDCAdmin.DC_GetCountryNames();
  47.             CommonUI.FillDropdown(ddlCountry, dsDetails.Tables[0], "COUNTRY_NAME", "COUNTRY_CODE", "--Select--", "--Select--");
  48.             objDCAdmin = null;
  49.         }
  50.         catch
  51.         {
  52.         }
  53.     }
  54.  
  55.     #region Web Form Designer generated code
  56.     override protected void OnInit(EventArgs e)
  57.     {
  58.         //
  59.         // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  60.         //
  61.         if (Session["UserID"] == null)
  62.         {
  63.             Session["UserID"] = "0";
  64.         }
  65.         InitializeComponent();
  66.         base.OnInit(e);
  67.         CommonUI.LoadDefaults(BodyID, litHeader, Session["UserID"].ToString());
  68.     }
  69.  
  70.     /// <summary>
  71.     /// Required method for Designer support - do not modify
  72.     /// the contents of this method with the code editor.
  73.     /// </summary>
  74.     private void InitializeComponent()
  75.     {
  76.         this.grdDetails.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grdDetails_ItemCommand);
  77.  
  78.     }
  79.     #endregion
  80.  
  81.  
  82.     protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
  83.     {
  84.         string CountryCode = Convert.ToString(ddlCountry.SelectedValue);
  85.         try
  86.         {
  87.             DC_Admin objDCAdmin = new DC_Admin(Session["UserId"].ToString());
  88.             DataSet dsDetails = objDCAdmin.DC_GetCityNames(CountryCode);
  89.             CommonUI.FillDropdown(ddlLocation, dsDetails.Tables[0], "CCM_CITY_DESC", "CCM_NEW_CTY_CODE", "--Select--", "--Select--");
  90.         }
  91.         catch
  92.         { }
  93.         ddlDiagnosticCenter.Items.Clear();
  94.         ddlDiagnosticCenter.Items.Insert(0, new ListItem("--Select--", "-1"));
  95.         ddlDiagnosticCenter.ClearSelection();
  96.         ddlDiagnosticCenter.Items[0].Selected = true;
  97.     }
  98.     protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
  99.     {
  100.         string CityCode = Convert.ToString(ddlLocation.SelectedValue);
  101.         try
  102.         {
  103.             DC_Admin objDCAdmin = new DC_Admin(Session["UserId"].ToString());
  104.             DataSet dsDetails = objDCAdmin.DC_GetDCName(CityCode);
  105.             CommonUI.FillDropdown(ddlDiagnosticCenter, dsDetails.Tables[0], "DC_VENDOR_NAME", "DC_VENDOR_ID", "--Select--", "--Select--");
  106.         }
  107.         catch
  108.         { }
  109.         ddlDiagnosticCenter.ClearSelection();
  110.         ddlDiagnosticCenter.Items[0].Selected = true;
  111.     }
  112.     protected void btnView_Click(object sender, EventArgs e)
  113.     {
  114.         CommonUI.CheckUser();
  115.         int CandidateId = -1;
  116.         if (txtCandId.Text.Trim() != "")
  117.             CandidateId = Convert.ToInt32(txtCandId.Text);
  118.         string CandidateName = "-1";
  119.         if (txtCandName.Text.Trim() != "")
  120.             CandidateName = txtCandName.Text.Trim();
  121.         string Country = Convert.ToString(ddlCountry.SelectedValue.Trim().ToString());
  122.         string Location = Convert.ToString(ddlLocation.SelectedValue.Trim().ToString());
  123.         string DCId = ddlDiagnosticCenter.SelectedValue.Trim().ToString();
  124.  
  125.         try
  126.         {
  127.             DC_Admin objDCAdmin = new DC_Admin(Session["UserId"].ToString());
  128.             DataSet dsDetails = objDCAdmin.DC_Getcandidate_Deatails(CandidateId, CandidateName, Country, Location, DCId, 2);
  129.             if (dsDetails.Tables[0].Rows.Count > 0)
  130.             {
  131.                 tblNoData.Visible = false;
  132.                 tblDetails.Visible = true;
  133.                 grdDetails.DataSource = dsDetails;
  134.                 grdDetails.DataBind();
  135.             }
  136.             else
  137.             {
  138.                 tblNoData.Visible = true;
  139.                 tblDetails.Visible = false;
  140.             }
  141.         }
  142.         catch
  143.         { }
  144.  
  145.     }
  146.  
  147.     protected void grdDetails_ItemCommand(object source, DataGridCommandEventArgs e)
  148.     {
  149.         if (e.CommandName.ToString() == "Reassign")
  150.         {
  151.             int CandidateId = Convert.ToInt32(e.Item.Cells[0].Text.ToString());
  152.             Response.Redirect("ReassignCandidate.aspx?CandidateId=" + CandidateId);
  153.         }
  154.     }
  155. }
pls suggest a solution for this

thanks&regards

Swathi

kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Nov 20 '08

re: ServerError:Object reference not set to an instance of an object.


Please do something first with your catch blocks and report back. Thanks.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#3: Nov 20 '08

re: ServerError:Object reference not set to an instance of an object.


The error message should also have contained the exact line number where that exception was thrown.
Reply


Similar .NET Framework bytes