473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.Net Class Import problems

Heya,
I might be going about this in completely the wrong fasion, I am more
of a PHP developer, but I am trying to build a collection of classes in
ASP.Net to implement in some aspx pages but also in other classes.
I can make an aspx page reference a class Class1 in namespace
NameSpace1 using

<%@ Assembly Src="../App_Code/NameSpace1.vb" %>

I also have a class in another file called DBConn which is in
NameSpace2. Intellisense lets me add 'Imports NameSpace2' or 'Imports
NameSpace2.DBConn' but when I reload the page I get

BC30466: Namespace or type 'NameSpace2' for the Imports 'NameSpace2'
cannot be found.

OR

'BC30466: Namespace or type 'DBconn' for the Imports
'NameSpace2.DBconn' cannot be found.

What am I doing wrong, what is the best way of includign one class
within another.. any help would be much appreciated!!

Nov 19 '05 #1
6 7014
chrisd wrote:
Heya,
I might be going about this in completely the wrong fasion, I am more
of a PHP developer, but I am trying to build a collection of classes
in ASP.Net to implement in some aspx pages but also in other classes.
I can make an aspx page reference a class Class1 in namespace
NameSpace1 using

<%@ Assembly Src="../App_Code/NameSpace1.vb" %>

I also have a class in another file called DBConn which is in
NameSpace2. Intellisense lets me add 'Imports NameSpace2' or 'Imports
NameSpace2.DBConn' but when I reload the page I get

BC30466: Namespace or type 'NameSpace2' for the Imports 'NameSpace2'
cannot be found.

OR

'BC30466: Namespace or type 'DBconn' for the Imports
'NameSpace2.DBconn' cannot be found.

What am I doing wrong, what is the best way of includign one class
within another.. any help would be much appreciated!!


The standard way of adding code to an aspx (or ascx) is to use a "codebehind" file.
This makes for a better separation of UI and code.

But this alone will not help you.

Are those classes in a separate project? If so, you need to add a "reference"
to that (class library?) project to you (web) project.
The "Imports" only provides a shorthand (if is't the same as "using" in C#):
you don't have to type the complete namespace for classes within the
"imported" namespace. The compiler will still want to know what is
in that namespace: therefore you need the reference.
(right click on the project, "add reference", ..)

By the way: you don't "include" a class within some other class. You
either create a instance of that class (and use it's instance methods)
or use "static" (sorry, don't know the VB term) methods directly.

Hans Kesting
Nov 19 '05 #2
Hi Hans,
Thanks for taking time to reply.
How do I create a 'codebehind' file?
The two classes are in the same folder (App_Code) .
I thought that Visual Studio would only allow intellisense auto filling
of namespaces if they are correctly referenced..
In any case, when I click on 'Add Reference' I have no idea what to
do.. the browse section is looking for dll's or exes (mine are VB.Net)
and it is not inutitive at all..

With regards to the 'includes' thing. This is just different
terminology, since in PHP, you include the physical file where the
class is found, and then add an object seperately.

In my current situation I have a public static class Class1 and a
public class DBconn..

Regards,
Chris Darke

Nov 19 '05 #3
chrisd wrote:
Hi Hans,
Thanks for taking time to reply.
How do I create a 'codebehind' file?
I don't know: when I add an aspx/ascx in VS2003, the aspx.cs/ascx.cs
(or I imagine, aspx.vb/ascx.vb) file gets added autimatically. From
what I have heard, there are more options in VS2005.
The two classes are in the same folder (App_Code) .
I thought that Visual Studio would only allow intellisense auto
filling of namespaces if they are correctly referenced..
In any case, when I click on 'Add Reference' I have no idea what to
do.. the browse section is looking for dll's or exes (mine are VB.Net)
and it is not inutitive at all..
Are those classes in a project (separate from your webproject) but in the
same solution? Then there is a "Projects" tab where you can select from
your projects (again, VS2003, but VS2005 shouldn't be too different here).

But you mention the App_Code directory. This is a directory in the
web-project (isn't it?) so you wouldn't need a reference to access
these classes. You can use them by using the correct namespace/classname
(or, with "Imports", just with the classname). I don't think you need
to specify any assembly, as it all works within your web-project assembly.

With regards to the 'includes' thing. This is just different
terminology, since in PHP, you include the physical file where the
class is found, and then add an object seperately.

In my current situation I have a public static class Class1 and a
public class DBconn..

Regards,
Chris Darke

Nov 19 '05 #4
heya,
the classes are within the same solution, but here is where things get
hazy.
I know that VS2005 referes to 'projects', 'solutions' and 'web sites'.
Now the web site is all there, and was originally built in ASP. I added
on the ASP.Net and VB.Net functions for the new functionality, with the
idea of porting the rest of the site over later (it is an insurance
management system)... so I never actually 'made a project' as such. I
am not sure if this has implications in terms of the structure, but I
just added class files by choosing 'add new item' and it auto created
the App_Code directory.
The fact is that thought the two class files are in the same App_Code
folder, and Intellisense picks them up fine, they dont see each other
at runtime.

Do you think it is the fact that they have to be built over a
'project'? If so, how is it done when you code it by hand without using
VS?

Thanks in advance!

Nov 19 '05 #5
Hi Chris:

If I were you I would start a new project completely seperate from your
website. Put the common code you need to reference from your pages
here. This is the general idea though you will have to do some
searching to do this manually. (Why do you have to do it manually? I
see above you're using VS2005 and looking for intellisense).

You need to build a dll which is of output type "class library." In
VS2005 this is easy enough to do: create a new project of this type.
Once you build your project into a dll, add a reference to the dll from
your website.

The reference needs to go in the bin directory of your website. If
there is no bin directory, create one underneath the root (sibling to
app_code) and put your dll there. You should be able to browse to the
directory where your dll was built.

At that point , you should be able to reference your classes and bring
em in with an import or using statement.

Regards,

Larry

Nov 19 '05 #6
Hi Larry,
Thanks for your reply..
So basically you are saying I need to build a seperate project from the
ground up for my asp.net code and I can then reference it from the site
files?
I guess I can do that.. just thought it would be possible to do that
without compiling a DLL.. since my aspx code can reference my vb class
and it all works fine to that point it seems a bit strange that for one
vb class to reference another i suddenly have to start building DLLs!
Oh microsoft..
And why do it manually? Well Visual Studio is just a tool for writing
the code is it now? just like with any other scripting language I just
thought it would be possible to write on a text editor and hence there
might be a cleaner, more manual way of doing it (i guess thats my
PHP/Perl mentality coming out)

Anyways thanks for all the feedback guys!

Nov 19 '05 #7

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

Similar topics

2
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e =...
1
by: Jeffrey Borkent | last post by:
Hi There, Please let me rephrase the problem as many people misunderstood what i was trying to ask. I know that the __init__ is the class constructor, that was not my question. under the...
6
by: Brent | last post by:
I'm having odd problems with the WebResponse class. Some servers are speedy, while others don't play along at all. Consider the following pages*: ...
5
by: S Borg | last post by:
Hello, I am running Python on Mac OS X. The interpreter has been great for learning the basics, but I would now like to be able to reuse code. How do I write reusable code? I have done it "The...
2
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
5
by: Mike Krell | last post by:
I'm running into problems trying to override __str__ on the path class from Jason Orendorff's path module (http://www.jorendorff.com/articles/python/path/src/path.py). My first attempt to do...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
1
by: bjwillykajilly | last post by:
Well, I got an assignment due this morning, so i guess ill end up turning it in a day late eh. anyways. I have a couple problems that I don't know what to do with. the objective is here: Write a...
3
by: jimgym1989 | last post by:
/*MY CONSOLE DOES NOT EXECUTE EVERY TIME I RUN MY PROGRAM WHAT HAPPEN? WHERE DID I GO WRONG? BUT THE PROCESS IS COMPLETED...I AM NEW IN JAVA PROGRAM AND THIS IS OUR NEW LESSON IN CLASS*/ import...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.