G
Guest
I could never get a solution to my delimma, so I'm trying in a last
(hopefully not futile) attempt to get past this damned issue!!! I would
REALLY appreciate someone helping my dumb-ass out here.
Alright, I have an asp.net program I started writing. I created a class
called tank, with some subclasses (round and square). I want to instantiate
this tank-type object at runtime, and assign it member values when the user
selects something. I keep getting an error about my instances referring to a
null object because the instances don't exist until the user makes a
selection at runtime. I tried this several ways, creating a class file and
just putting them directly under the agitatorSz namespace, but still seems to
be some kind of scope issue.
Here's my class code and my application code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace agitatorSz
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class main_frm : System.Web.UI.Page
{
public System.Web.UI.WebControls.Button tankType_btn;
protected System.Web.UI.WebControls.Button dimensions_btn;
protected System.Web.UI.WebControls.TextBox impellers_txt;
protected System.Web.UI.WebControls.TextBox agitators_txt;
protected System.Web.UI.WebControls.Label volume_txt;
protected System.Web.UI.WebControls.Label turnover_txt;
protected System.Web.UI.WebControls.Label gpm_txt;
protected System.Web.UI.WebControls.DataGrid product_grd;
protected System.Web.UI.WebControls.TextBox length_txt;
protected System.Web.UI.WebControls.TextBox width_txt;
protected System.Web.UI.WebControls.TextBox diameter_txt;
protected System.Web.UI.WebControls.TextBox depth_txt;
protected System.Web.UI.WebControls.Button model_btn;
protected System.Web.UI.WebControls.DropDownList model_ddl;
protected System.Web.UI.WebControls.Button powerSrc_btn;
protected System.Web.UI.WebControls.DropDownList power_ddl;
protected System.Web.UI.WebControls.TextBox maxMudLvl_txt;
protected System.Web.UI.WebControls.DropDownList tankType_ddl;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#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);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tankType_btn.Click += new
System.EventHandler(this.tankType_btn_Click);
this.model_btn.Click += new System.EventHandler(this.model_btn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void tankType_btn_Click(object sender, System.EventArgs e)
{
tankTypeVar=tankType_ddl.SelectedItem.Value;
switch(tankType_ddl.SelectedItem.Value)
{
case "1":
{
roundTank rt = new roundTank();
rt.orientation="test1";
//enable controls relevant to class, disable others
diameter_txt.Enabled=true;
length_txt.Enabled=false;
width_txt.Enabled=false;
break;
}
case "2":
{
squareTank st = new squareTank();
st.orientation="test2";
//enable controls relevant to class
length_txt.Enabled=true;
width_txt.Enabled=true;
diameter_txt.Enabled=false;
break;
}
}
}
private void model_btn_Click(object sender, System.EventArgs e)
{
if(rt!=null)
{
depth_txt.Text=rt.orientation;
}
if(st!=null)
{
depth_txt.Text=st.orientation;
}
}
}
}
------------
class code
------------
using System;
namespace agitatorSz
{
/// <summary>
/// Summary description for tank.
/// </summary>
public class tank
{
public tank()
{
}
public float powerSource;
public string orientation; //horizontal or vertical (values are: H or V)
public float depth;
public float maxMudLvl;
public int agitatorQty;
public int impellerQty;
public float mudVolume;
public float turnoverRatio;
public float GPM;
}
public class roundTank:tank
{
public roundTank()
{
}
public float diameter;
}
public class squareTank:tank
{
public squareTank()
{
}
public float length;
public float width;
}
}
(hopefully not futile) attempt to get past this damned issue!!! I would
REALLY appreciate someone helping my dumb-ass out here.
Alright, I have an asp.net program I started writing. I created a class
called tank, with some subclasses (round and square). I want to instantiate
this tank-type object at runtime, and assign it member values when the user
selects something. I keep getting an error about my instances referring to a
null object because the instances don't exist until the user makes a
selection at runtime. I tried this several ways, creating a class file and
just putting them directly under the agitatorSz namespace, but still seems to
be some kind of scope issue.
Here's my class code and my application code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace agitatorSz
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class main_frm : System.Web.UI.Page
{
public System.Web.UI.WebControls.Button tankType_btn;
protected System.Web.UI.WebControls.Button dimensions_btn;
protected System.Web.UI.WebControls.TextBox impellers_txt;
protected System.Web.UI.WebControls.TextBox agitators_txt;
protected System.Web.UI.WebControls.Label volume_txt;
protected System.Web.UI.WebControls.Label turnover_txt;
protected System.Web.UI.WebControls.Label gpm_txt;
protected System.Web.UI.WebControls.DataGrid product_grd;
protected System.Web.UI.WebControls.TextBox length_txt;
protected System.Web.UI.WebControls.TextBox width_txt;
protected System.Web.UI.WebControls.TextBox diameter_txt;
protected System.Web.UI.WebControls.TextBox depth_txt;
protected System.Web.UI.WebControls.Button model_btn;
protected System.Web.UI.WebControls.DropDownList model_ddl;
protected System.Web.UI.WebControls.Button powerSrc_btn;
protected System.Web.UI.WebControls.DropDownList power_ddl;
protected System.Web.UI.WebControls.TextBox maxMudLvl_txt;
protected System.Web.UI.WebControls.DropDownList tankType_ddl;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#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);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tankType_btn.Click += new
System.EventHandler(this.tankType_btn_Click);
this.model_btn.Click += new System.EventHandler(this.model_btn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void tankType_btn_Click(object sender, System.EventArgs e)
{
tankTypeVar=tankType_ddl.SelectedItem.Value;
switch(tankType_ddl.SelectedItem.Value)
{
case "1":
{
roundTank rt = new roundTank();
rt.orientation="test1";
//enable controls relevant to class, disable others
diameter_txt.Enabled=true;
length_txt.Enabled=false;
width_txt.Enabled=false;
break;
}
case "2":
{
squareTank st = new squareTank();
st.orientation="test2";
//enable controls relevant to class
length_txt.Enabled=true;
width_txt.Enabled=true;
diameter_txt.Enabled=false;
break;
}
}
}
private void model_btn_Click(object sender, System.EventArgs e)
{
if(rt!=null)
{
depth_txt.Text=rt.orientation;
}
if(st!=null)
{
depth_txt.Text=st.orientation;
}
}
}
}
------------
class code
------------
using System;
namespace agitatorSz
{
/// <summary>
/// Summary description for tank.
/// </summary>
public class tank
{
public tank()
{
}
public float powerSource;
public string orientation; //horizontal or vertical (values are: H or V)
public float depth;
public float maxMudLvl;
public int agitatorQty;
public int impellerQty;
public float mudVolume;
public float turnoverRatio;
public float GPM;
}
public class roundTank:tank
{
public roundTank()
{
}
public float diameter;
}
public class squareTank:tank
{
public squareTank()
{
}
public float length;
public float width;
}
}