New .net 2.0 syntax...namespaces? Shared methods?

D

Daniel

Hey guys

I had a site in .net 1.1 and have just moved it to .net 2.0.

A strange thing, in .net 1 when you create a project it puts it in a
namespace, in 2.0 it doesn't?

Also when in a namespace one form can't access methods in another, and when
not in a namespace same issue.

However a dll i made in my orignal with a namespace was fine.

So is this a new syntax thing, that in ,net 2.0 one forms code behind file
methods cannot access another forms codebehind class?

For example:

class Form 1 has method MyForm1Method()

class Form 2 has method MyForm2Method();

in class Form1 i used to be able to;

Form2 f2 = new Form2();
f2.MyForm2Method();

But now it can't find Form2.

Let us know if this is new syntax. I am guessing it is to ensure that all
shared methods across multiple forms are placed in a referenced dll giving
all forms access. Let me know.

D
 
A

apathetic

Daniel said:
A strange thing, in .net 1 when you create a project it puts it in a
namespace, in 2.0 it doesn't?

This is the default, but you can still wrap your classes in a namespace
if you like.
Also when in a namespace one form can't access methods in another, and when
not in a namespace same issue.

Have you checked that both the page class and the methods are public?

The way ASP.NET 2.0 works is that each page is compiled as needed. I'm
not sure if the code for the second form you are trying to access is
even guaranteed to be there. You should put all classes to be shared
by other pages either into App_Code or a different assembly.

As a side note, this sounds like a bad habit - why would you want to
call a method on a page from another page?

apathetic
 
D

Daniel

Yes i a agree it is a bad habit. I now do it all via shared livrary classes
in dlls. Its old code i am bringing up to scratch that was made in stupid
deadlines.

What is App_Code? I haven't heard of that. Is it just a folder tha is
global? Should i drop all my cs files in there?

And yes classes are all public....when you say page class you mean the
codebehind cs file page yes? That class is public.

D
 
M

Mark Fitzpatrick

Take a look at the web application projects. This project is more akin to
the VS.Net 2003 web application.
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

The VS 2005 Web site project is very different. One of the reasons you are
running into these issues is the code is not precompiled into a single dll.
It will end up as many dll files. You'll find that files within the same
directory may be able to reference eachother, but not files in another
directory. The Web application project was introduced because the change was
not working out for a significant number of users.
 
G

GroupReader

1. ASP.Net 2005 website projects have several "special folders."
Search google for App_Code and App_Data. Shared code pretty much needs
to go in app code in order to be accesible.

2. In 2005, every subfolder is compiled into a separate assembly,
regardless of namespace. Before, in 2003, it was one assembly per
namespace (or was it one assembly for the whole site?). So,
unfortunately, there will be scoping issues when upgrading from 1.x to
2.0 because files are no longer in the same assembly.

3. As Mark F. mentioned above, enough people complained about the new
application model that MS released a "workaround" to make your 2005
"web site apps" behave more like 2003 "web projects". I've used it and
it works... but I try not to.. I think it's better to evolve and adapt.

4. I forgot to mention this... and this is huge... in 2005, you no
longer have a "project" that contains .aspx files. You have a
"website" that maps to a folder on your hard drive. Whatever files are
in your folder are considered "in your website." To remove a file, you
need to delete it. There's no concept of "adding/removing" files from
a project. I know I didn't explain this very well.
 
D

Daniel

Ok thanks guys that explains A LOT of things. Ok so when i upload my site i
upload the full site directory.

The scoping issues, ok i see why people moand, but i agree evolve and adapt
always best measure.

Thanks for help
 

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