Here is my web form code and my class code:
-------------------------------------
Web Form (main_frm.aspx)
-------------------------------------
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
{
protected System.Web.UI.WebControls.Label title_lbl;
protected System.Web.UI.WebControls.Label tank_lbl;
protected System.Web.UI.WebControls.DropDownList tank_cbo;
protected System.Web.UI.WebControls.TextBox length_txt;
protected System.Web.UI.WebControls.TextBox width_txt;
protected System.Web.UI.WebControls.TextBox depth_txt;
protected System.Web.UI.WebControls.TextBox mudLvl_txt;
protected System.Web.UI.WebControls.TextBox diameter_txt;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label diameter_lbl;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Button tank_btn;
protected System.Web.UI.WebControls.Button dimension_btn;
protected System.Web.UI.WebControls.Label Logo_lbl;
protected System.Web.UI.WebControls.Label dimensionErr_lbl;
//Public variable for hoding the tank type selected
string tankType;
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.dimension_btn.Click += new
System.EventHandler(this.dimension_btn_Click);
this.tank_btn.Click += new System.EventHandler(this.tank_btn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void tank_btn_Click(object sender, System.EventArgs e)
{
tankType=tank_cbo.SelectedItem.Value;
//get the tank type selection and instantiate the "tank" class
//initialize the next group of data entry controls (text boxes)
switch(tank_cbo.SelectedItem.Value)
{
case "1":
{
tank rt = new roundTank();
length_txt.Enabled = false;
width_txt.Enabled = false;
depth_txt.Enabled = true;
diameter_txt.Enabled = true;
mudLvl_txt.Enabled = true;
//declare class round tank and initialize
break;
}
case "2":
{
tank st = new squareTank();
length_txt.Enabled = true;
width_txt.Enabled = true;
depth_txt.Enabled = true;
diameter_txt.Enabled = false;
mudLvl_txt.Enabled = true;
break;
}
}
}
private void dimension_btn_Click(object sender, System.EventArgs e)
{
//validate data entry
switch(tankType)
{
case "1":
{
if(diameter_txt.Text=="" || depth_txt.Text=="" || mudLvl_txt.Text=="")
{
dimensionErr_lbl.Text="All appropriate dimensions must be entered";
}
else
{
rt.depth=2;
depth_txt.Text=rt.depth;
}
break;
}
case "2":
{
if(length_txt.Text=="")
{
dimensionErr_lbl.Text="All appropriate dimensions must be entered";
}
else
{
st.depth=2;
depth_txt.Text=st.depth;
}
break;
}
}
}
}
}
-------------------------------------
class (tank.cs)
-------------------------------------
using System;
namespace agitatorSz
{
/// <summary>
/// Summary description for tank.
/// </summary>
public class tank
{
public tank()
{
}
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;
}
}
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
I just did it with the code you posted and worked, make sure that both files
( the one with the classes definition and where you use them) have the same
namespace declared.
Are they in the same project?
I think that the error should be somewhere else, if the compiler does not
find roundTank it should say :
The type or namespace name 'roundTank'
but definetly no 'rt'
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"StillStuckOnJava" <St**************@discussions.microsoft.com> wrote in
message news:F6**********************************@microsof t.com... That's exactly what I did and this is what I get when I try to instantiate
(rountTank rt = new roundTank(); OR tank rt = new roundTank();)
ERROR:
The type or namespace name 'rt' could not be found (are you missing a
using
directive or an assembly reference?)
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
In the project explorer right click in the project name. Add New / Add
Class
It will create a new file with a class on it in the correct namespace
Just include your classes there
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"StillStuckOnJava" <St**************@discussions.microsoft.com> wrote in
message news:02**********************************@microsof t.com...
> I'm using visual studio to create a web application, but I'm having
> trouble
> using a few classes that I've defined:
>
> public class tank
> {
> public tank()
> {
> }
> 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;
> }
>
> I tried putting them within the application namespace, but that didn't
> work.
> Then I tried putting them in a class file, and that still didn't work.
> The
> intellitype seems to work when I declare a new instance of the class,
> but
> when I try to access the members, it doesn't.
>
> I've searched and flipped many pages, but I can't find anything that
> says
> simply: here's where you define classes or global variables in an
> ASP.NET
> visual studio project.
>
> Someone please forgive my ignorance and let me know. Thanks.