Class not visable - problem when not using visual studio

S

Stephen Adam

Hi there,

I've just started a c# project at work where I cannot use Visual Studio. I
am trying to pass variables from one form to another. When I try to create
an instance of the sending class in the receiving class I get a "The type or
namespace name 'XXXX' could not be found (are you missing a using directive
or an assembly reference?)" Error.

It seems that even though the sending class resides in the same folder as
the receiving class it still cannot be seen. I think it may have something
to do with the lack of a csproj file telling the compiler where the classes
are, though I have even tried editing a cjproj file and using it. IT might
also be because I'm not compiling my classes first, instead I'm just giving
an SRC and doing it on the fly (<%@ Page language="C#"
Src="/testbed/Send.cs" ).

I have included all the code to show what my problem is, can anyone help?
Would be very grateful :)



SEND.ASPX
<%@ Page language="C#" Src="/testbed/Send.cs" Inherits="Test.Send" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<form id="frmOne" action="Send.aspx" method="post" runat="server">

<asp:Button id="btnSend" runat="server" text="Send"> </asp:Button>

</form>
</body>
</html>

SEND.CS
namespace Test {

using System;
using System.Data;
using System.Data.SqlClient;

using System.Web;
using System.Web.UI;

using System.Web.UI.WebControls;


public class Send : System.Web.UI.Page {

protected System.Web.UI.WebControls.Button btnSend;

protected string StringToSend; // Add / Edit / Delete

protected override void OnInit(EventArgs e){
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent(){
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);
}

protected void Page_Load(Object sender, EventArgs e) {
}

private void btnSend_Click(object sender, System.EventArgs e){
StringToSend = "Sent Text";
Server.Transfer("Receive.aspx");
}


// Getters for passing form vars
public string GetStringToSend(){
return StringToSend;
}
}

}


RECEIVE.ASPX

<%@ Page language="C#" Src="/testbed/Receive.cs" Inherits="Test.Receive" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<body>
<form id="frmOne" action="Receive.aspx" method="post" runat="server">
<table>
<asp:Lable runat="server" id="lblTest"> </asp:Lable>
</table>
</form>

RECEIVE.CS
namespace Test {

using System;
using System.Data;
using System.Web.UI.WebControls;


public class Receive : System.Web.UI.Page {

protected System.Web.UI.WebControls.Label lblTest;

protected string ReceivedString;


protected override void OnInit(EventArgs e){
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent(){
}

protected void Page_Load(Object sender, EventArgs e) {
if (!IsPostBack){

//Create Reference To NewsSectionSelect Page and Get Values
Send frmSend = (Send) Context.Handler;

ReceivedString = frmSend.GetStringToSend();

lblTest.Text = ReceivedString;
}

}
}
}
 
S

Stefan

Hi,

I beleive your problem is the lack of namespace references in
RECIEVE.CS.

Try adding:

using System.Web;
using System.Web.UI;

You are makeing reference to them in SEND.CS but not RECIEVE.CS.


Happy Coding,

Stefan
C# GURU
www.DotNETovation.com

"You always have to look beyond the horizon and can never be complacent
-- God forbid we become complacent."

Jozef Straus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top