Note that there are some explanatory texts on larger screens.

plurals
  1. POCall to methods results in "Message: Object reference not set to an instance of an object."
    primarykey
    data
    text
    <p>I cannot figure out why I any of these methods (load_qc_form(); enable_qc_form();disable_qc_form();) I get the "Message: Object reference not set to an instance of an object." message.</p> <p>How can calling a method return null??</p> <p>Here is my entire code. I am new to C# and am trying to update an existing page. Could someone point me in the right direction? </p> <p>I want to be able to call these methods from anywhere in the application. </p> <pre><code> namespace test_page { using System; //using System.Windows.Forms; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; /// &lt;summary&gt; /// Summary description for ProductionQC. /// &lt;/summary&gt; /// public class hendrix : System.Web.UI.UserControl { #region class_variable_declarations //Test Boxes protected System.Web.UI.WebControls.TextBox boxOrder; protected System.Web.UI.WebControls.TextBox boxBox; protected System.Web.UI.WebControls.TextBox boxPallet; protected System.Web.UI.WebControls.TextBox boxPulpTemp; protected System.Web.UI.WebControls.TextBox boxComments; protected System.Web.UI.WebControls.TextBox boxMajdef1; protected System.Web.UI.WebControls.TextBox boxMajdef2; protected System.Web.UI.WebControls.TextBox boxMajdef3; protected System.Web.UI.WebControls.TextBox boxMindef1; protected System.Web.UI.WebControls.TextBox boxMindef2; protected System.Web.UI.WebControls.TextBox boxMindef3; protected System.Web.UI.WebControls.TextBox boxSamples; //drop down lists protected System.Web.UI.WebControls.DropDownList listYN; protected System.Web.UI.WebControls.DropDownList listMaj1; protected System.Web.UI.WebControls.DropDownList listMaj2; protected System.Web.UI.WebControls.DropDownList listMaj3; protected System.Web.UI.WebControls.DropDownList listMin1; protected System.Web.UI.WebControls.DropDownList listMin2; protected System.Web.UI.WebControls.DropDownList listMin3; protected System.Web.UI.WebControls.DropDownList listRecorder; //labels protected System.Web.UI.WebControls.Label lblPalletTag; protected System.Web.UI.WebControls.Label lblmajdef1; protected System.Web.UI.WebControls.Label lblmajdef2; protected System.Web.UI.WebControls.Label lblmajdef3; protected System.Web.UI.WebControls.Label lblmindef1; protected System.Web.UI.WebControls.Label lblmindef2; protected System.Web.UI.WebControls.Label lblmindef3; protected System.Web.UI.WebControls.Label lblPulpTemp; protected System.Web.UI.WebControls.Label lblComments; protected System.Web.UI.WebControls.Label lblPackageCorrect; protected System.Web.UI.WebControls.Label lblTotSamples; protected System.Web.UI.WebControls.Label lblrecorder; //Buttons protected System.Web.UI.WebControls.Button btnGo; protected System.Web.UI.WebControls.Button btnGo2; protected System.Web.UI.WebControls.Button btnGo3; protected System.Web.UI.WebControls.Button btnClear; //Gridviews protected System.Web.UI.WebControls.GridView grdDisplayOrd; protected System.Web.UI.WebControls.GridView grdDisplayBox; //Data connections - adapters protected System.Data.SqlClient.SqlCommand cmdData; protected System.Data.SqlClient.SqlConnection sqlConnection1; protected System.Data.SqlClient.SqlDataReader dataReader; #endregion class_variable_declarations private void Page_Load(object sender, System.EventArgs e) { //initializePage(); // Put user code to initialize the page here if (!this.Page.IsPostBack) { //load_qc_form(); //disable_qc_form(); } } //private void initializePage() // { // throw new NotImplementedException(); //} #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; private void InitializeComponent() { this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.btnGo.Click += new System.EventHandler(this.btnGo_Click); this.btnGo2.Click += new System.EventHandler(this.btnGo2_Click); // this.btnGo3.Click += new System.EventHandler(this.btnGo3_Click); this.btnClear.Click += new EventHandler(this.btnClear_Click); // // sqlConnection1 // this.sqlConnection1.ConnectionString = "workstation id=\"******";packet size=4096;user id=******;data source=\"******";persis" + "t security info=True;initial catalog=****;password=**********"; this.Load += new System.EventHandler(this.Page_Load); } #endregion // public virtual string DisplayMember { get; set; } //get and display order data private void btnGo_Click(object sender, System.EventArgs e) { { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Select ord.order_number as Order#,var.description as Description,grd.description as Grade, " + "size.description as Size,pkg.description as Pkg, ord.container_type as Pallet " + "FROM t_item_master itm INNER JOIN t_order_detail ord (NOLOCK) ON ord.item_number = itm.item_number " + "LEFT OUTER JOIN t_package pkg (NOLOCK) ON pkg.package_name = itm.product_package_code " + "LEFT OUTER JOIN t_grade grd (NOLOCK) ON grd.grade_id = itm.grade_id " + "LEFT OUTER JOIN t_size size (NOLOCK) ON size.size_id = itm.size_id AND size.package_id = pkg.package_id " + "LEFT OUTER JOIN t_variety var (NOLOCK) ON var.variety_id = itm.variety_id " + "WHERE order_number like @order_number"; cmd.Parameters.Add("@order_number", SqlDbType.VarChar).Value = boxOrder.Text; cmd.CommandType = CommandType.Text; cmd.Connection = this.sqlConnection1; this.sqlConnection1.Open(); this.grdDisplayOrd.Visible = true; SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adpt.Fill(ds); grdDisplayOrd.DataSource = ds; grdDisplayOrd.DataBind(); this.sqlConnection1.Close(); } } // get and display box data private void btnGo2_Click(object sender, System.EventArgs e) { { load_qc_form(); SqlCommand cmd = new SqlCommand(); HyperLink test_link1 = new HyperLink(); cmd.CommandText = "select " + "item_number as Item#, " + "description as Desctiption, " + "grower_lot as Lot#, " + "pack_date as Packed " + "from v_box_data where box_id = @box_id"; cmd.Parameters.Add("@box_id", SqlDbType.VarChar).Value = boxBox.Text; cmd.CommandType = CommandType.Text; cmd.Connection = this.sqlConnection1; this.sqlConnection1.Open(); this.grdDisplayBox.Visible = true; SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adpt.Fill(ds); grdDisplayBox.DataSource = ds; grdDisplayBox.DataBind(); this.sqlConnection1.Close(); } } private void load_qc_form() { #region declare_variables // string pallet_tag; //string correct_package; //string total_samples; //string majdef1; //string majdef2; //string majdef3; // string mindef1; // string mindef2; // string mindef3; // string majcnt1; // string majcnt2; //string majcnt3; // string mincnt1; // string mincnt2; // string mincnt3; // string pulptemp; // string comments; string recorder; #endregion declare_variables #region fill_list_recorder try { listRecorder.Items.Clear(); recorder = "select EMPID,FIRSTNAME+' '+LASTNAME from t_famous_employee " + "where COSTCENTERNAME like 'Quality Control - 2011' " + "and HOMECREWID LIKE 'Shipping' "; cmdData = new System.Data.SqlClient.SqlCommand(recorder, this.sqlConnection1); cmdData.Connection = this.sqlConnection1; this.sqlConnection1.Open(); SqlDataAdapter da = new SqlDataAdapter(cmdData); DataTable dt = new DataTable(); da.Fill(dt); listRecorder.DataBind(); listRecorder.DataSource = dt; listRecorder.DataValueField = "EMPID"; listRecorder.DataTextField = "FIRSTNAME+' '+LASTNAME"; this.listRecorder.Items.Insert(0, "FIRSTNAME+' '+LASTNAME"); } catch (Exception) { } this.dataReader.Close(); #endregion } private void btnGo3_Click(object sender, System.EventArgs e) { { } } private void btnClear_Click(object sender, System.EventArgs e) { { this.boxOrder.Text = ""; this.boxBox.Text = ""; this.grdDisplayOrd.Visible = false; this.grdDisplayBox.Visible = false; //disable_qc_form(); } } private void enable_qc_form() { this.listMaj1.Enabled = true; this.listMaj2.Enabled = true; this.listMaj3.Enabled = true; this.listMin1.Enabled = true; this.listMin2.Enabled = true; this.listMin3.Enabled = true; this.listYN.Enabled = true; this.listMaj1.Enabled = true; this.listMaj2.Enabled = true; this.listMaj3.Enabled = true; this.listMin1.Enabled = true; this.listMin2.Enabled = true; this.listMin3.Enabled = true; this.boxComments.Enabled = true; this.boxMajdef1.Enabled = true; this.boxMajdef2.Enabled = true; this.boxMajdef3.Enabled = true; this.boxMindef1.Enabled = true; this.boxMindef2.Enabled = true; this.boxMindef3.Enabled = true; this.boxPallet.Enabled = true; this.boxPulpTemp.Enabled = true; this.boxSamples.Enabled = true; this.lblComments.Enabled = true; this.lblmajdef1.Enabled = true; this.lblmajdef2.Enabled = true; this.lblmajdef3.Enabled = true; this.lblmindef1.Enabled = true; this.lblmindef2.Enabled = true; this.lblmindef3.Enabled = true; this.lblPackageCorrect.Enabled = true; this.lblPalletTag.Enabled = true; this.lblPulpTemp.Enabled = true; this.lblTotSamples.Enabled = true; } private void disable_qc_form() { this.listMaj1.Enabled = false; this.listMaj2.Enabled = false; this.listMaj3.Enabled = false; this.listMin1.Enabled = false; this.listMin2.Enabled = false; this.listMin3.Enabled = false; this.listYN.Enabled = false; this.listMaj1.Enabled = false; this.listMaj2.Enabled = false; this.listMaj3.Enabled = false; this.listMin1.Enabled = false; this.listMin2.Enabled = false; this.listMin3.Enabled = false; this.boxComments.Enabled = false; this.boxMajdef1.Enabled = false; this.boxMajdef2.Enabled = false; this.boxMajdef3.Enabled = false; this.boxMindef1.Enabled = false; this.boxMindef2.Enabled = false; this.boxMindef3.Enabled = false; this.boxPallet.Enabled = false; this.boxPulpTemp.Enabled = false; this.boxSamples.Enabled = false; this.lblComments.Enabled = false; this.lblmajdef1.Enabled = false; this.lblmajdef2.Enabled = false; this.lblmajdef3.Enabled = false; this.lblmindef1.Enabled = false; this.lblmindef2.Enabled = false; this.lblmindef3.Enabled = false; this.lblPackageCorrect.Enabled = false; this.lblPalletTag.Enabled = false; this.lblPulpTemp.Enabled = false; this.lblTotSamples.Enabled = false; } } } </code></pre> <p>So I need to be able to call the method to test my first dropdown list.</p> <p>Thank you in advance for your help!! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload