473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

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
Oct 17 '06 #1
5 1330
Daniel wrote:
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

Oct 17 '06 #2
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
"apathetic" <ap*************@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Daniel wrote:
>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

Oct 17 '06 #3
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.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Daniel" <Da*****@vestryonline.comwrote in message
news:OK**************@TK2MSFTNGP04.phx.gbl...
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
"apathetic" <ap*************@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>Daniel wrote:
>>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


Oct 17 '06 #4
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.

Oct 18 '06 #5
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

"Daniel" <Da*****@vestryonline.comwrote in message
news:OO*************@TK2MSFTNGP05.phx.gbl...
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

Oct 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
2
by: Raymond Lewallen | last post by:
It could help if you understood the project I work on a bit, but I can't tell you anything about it, so do the best you can under that pretense. Lets say you have a global assembly supporting...
1
by: Andy Lomax | last post by:
I'm converting a library I've written so that all my code is in namespace 'foo' (previously all my external symbols had a 'foo_' prefix; I'm new to C++). Question: my source files now have a...
8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
5
by: M Shafaat | last post by:
Hi, I want to develop a number of generic components which I intend to use in different applications. Is it a good idea to put all these generic components in one and the same namespace, e.g....
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
6
by: douglass_davis | last post by:
Is the whole System namespace automatically imported?
5
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.