Not able to put class into namespace

K

K Viltersten

I've designed a class as below.

public partial class Test
: System.Web.UI.Page {
protected void Page_Load(
object sender, EventArgs e)
{
...
ThatLabel.Text = "!";
...
}
...
}

Now, i'd like to place it into a
namespace but when i do that, it seems
that the controls i refer to (ThatLabel)
are, do not exist in the current
context.

What is the reason for that and how can
i resolve the problem?

The only guess i have is that the class
begin partial, has other parts of it
somewhere and THAT OTHER part, declaring
and creating the actual control, gets
placed OUTSIDE the new namespace.
However, i haven't found "the rest" of
the code. How can i get to it?
 
C

Cowboy \(Gregory A. Beamer\)

ThatLabel? Is this a control you have created? If so, you have to reference
its namespace once you place your Test class in a namespace.

A namespace is a logical container. It can only see in containers it knows
about through using statements (Imports in VB). The original was in the same
namespace as the control in question and when you box it, it isn't. So, you
have to inform your Test class of the other container(s) for its controls.
Make sense?
 
K

K Viltersten

ThatLabel is jsut an asp:Label, nothing more.
However, when i enclose the class Test with
a namespace-thingy, i get red line under its
name, as if it's not known.

So, it works here:

public partial class Test : System.Web.UI.Page {
protected void Page_Load(
object sender, EventArgs e)
{ ThatLabel.Text = "!"; }
}

but not here:

namespace SomeNiceName {
public partial class Test : System.Web.UI.Page {
protected void Page_Load(
object sender, EventArgs e)
{ ThatLabel.Text = "!"; }
}
}

The component is placed on the page using this.

<asp:Label runat="server" ID="ThatLabel"></asp:Label>

Also, as i pointed out before, i can't find the
other part(s) of the partial class that VS
created for me autoamtically. Where is it?

--
Regards
K Viltersten

ThatLabel? Is this a control you have created? If so, you have to
reference its namespace once you place your Test class in a namespace.

A namespace is a logical container. It can only see in containers it knows
about through using statements (Imports in VB). The original was in the
same namespace as the control in question and when you box it, it isn't.
So, you have to inform your Test class of the other container(s) for its
controls. Make sense?
 
H

Hans Kesting

K Viltersten laid this down on his screen :
ThatLabel is jsut an asp:Label, nothing more.
However, when i enclose the class Test with
a namespace-thingy, i get red line under its
name, as if it's not known.

So, it works here:

public partial class Test : System.Web.UI.Page {
protected void Page_Load(
object sender, EventArgs e)
{ ThatLabel.Text = "!"; }
}

but not here:

namespace SomeNiceName {
public partial class Test : System.Web.UI.Page {
protected void Page_Load(
object sender, EventArgs e)
{ ThatLabel.Text = "!"; }
}
}

The component is placed on the page using this.

<asp:Label runat="server" ID="ThatLabel"></asp:Label>

Also, as i pointed out before, i can't find the
other part(s) of the partial class that VS
created for me autoamtically. Where is it?

VS probably created a Test.aspx.Designer.cs file. In the solution
explorer this should be located right next to the codebehind file
Test.aspx.cs.

Hans Kesting
 
K

K Viltersten

The only guess i have is that the class
VS probably created a Test.aspx.Designer.cs
file. In the solution explorer this should
be located right next to the codebehind
file Test.aspx.cs.

As far as i can see, there are only two
files with "Test" in the name. Those are:

Test.aspx
Test.aspx.cs

There are no *.Designer.* at all in the
view. I suppose they are there but are not
viewed to me. How can i get there?
 
B

bruce barker

asp.net uses partial the partial class model to combine the codebenind
file and the class file generated by the page compile.

if the namspace of the page (which defines the control names) is
different then the namespace in codebehind, then you need to fully
qualify the control names as they are in a differnt namespace.

I believe the default namespace for the page is ASP. You could also make
the namespace of the page match the codebehind namespace via the
ClassName in the <@page> directive.

note: designer files are only required with web applications, and not
sure if they support namespaces.

-- bruce (sqlwork.com)
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top