Solved

Imports for aspx page that Inherits: Reusing code

Posted on 2004-09-18
7
657 Views
Last Modified: 2008-02-01
I have this at the top of my aspx page which works fine
<%@ Page Inherits="GettingStarted" Src="002-GettingStarted.vb" Language="VB" %>

But in the code file
002-GettingStarted.vb

I have an Inports to another class that is in the file MySqlApi.vb
Imports MySqlApi

But, when I run the aspx page, it complains about the Imports line.

How do I let it see the class?
0
Comment
Question by:rcagley
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 24

Expert Comment

by:Justin_W
Comment Utility
Use:
   <%@ Import namespace="MySqlApi" %>

Import statements only affect the file they are located within.  So you have to either fully qualify all code or import in both files.
0
 
LVL 5

Expert Comment

by:ajitanand
Comment Utility
hello,

You can only Import NameSpaces, and NOT Classes directly!

So if you have the class MySqlApi in MySqlApi.vb, there are 2 possible ways out:

1. If the class MySqlApi belongs to another NameSpace (for e.g. as MyClasses.MySqlApi), you need to import MyClasses namespace, in your vbcode, to use the class. And if this NameSpace exists in another Assembly (.Net dll), then you need to add its reference in your VB Project that contains your 002-GettingStarted.vb file.

2. If the MySqlApi exists in the same NameSpace as your GettingStarted class, and in the same project, you need not specify ANY Imports statement in your vb code. It is available directly in your VB Project in VS.Net

------------------------

Let me know if this helps / does not help.

rgds,
Ajit Anand
0
 

Author Comment

by:rcagley
Comment Utility
Sorry, I'm not quite there. I'm using webmatrix and not VS.NET (which I'm more used to).

I guess generally I don't understand how to use classes that are in separate files. I can include one file with this
<%@ Page Inherits="TSIC.GettingStarted" Src="002-GettingStarted.vb" Language="VB"  %>

so then in 0002-GettingStarted.vb I want to access a class in a separate file MySqlApi.vb *and* this file wants to access another class which is in a dll i.e.
Imports CoreLab.MySql

Ajit, you're right normally I would just add the reference in my VS.NET project but I don't know how to do that with just my .vb and .aspx files. Any ideas?

thanks for the help
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Accepted Solution

by:
ajitanand earned 500 total points
Comment Utility
In these cases:

Step 1. Here you just need this command to compile your vb files. (It compiles all you vb files in current directory):

vbc /r:CoreLab.dll /r:System.dll /r:System.Web.dll /target:library /out:TSIC.dll /imports:CoreLab.MySql *.vb

[considering that CoreLab.MySQL.* is your assembly name. i.e. a class here will be like CoreLab.MySql.Class1, else you may simply try with /imports:CoreLab]

/r - to add a reference to a dll
/imports - to import a namespace from a dll, used in your .vb files


Step 2. In your ASPX files, no need to use the Src="" attribute. If you place the dll in your bin folder, just specify the Inherits attribute properly, it will work. Take this as example. It works, if you want to follow the code behind concept in Webmatrix as well.

<%@ Page Language="VB" Inherits="StudioWebControls.SmartPage" %>
<%@ Register TagPrefix="uc1" Namespace="MyWebControls" Assembly="MyWebControls" %>
<%@ import Namespace="System.Resources" %>
<%@ import Namespace="System.Globalization" %>


------------------------------

Hope this helps.

rgds,
Ajit Anand
0
 
LVL 24

Expert Comment

by:Justin_W
Comment Utility
As long as the DLL is in the BIN directory of your web app, your web app will see the DLL.  Then you just need to fully qualify, like this:
   CoreLab.MySql.SomeClass.SomeFunction()
or import, as I showed above.
0
 

Author Comment

by:rcagley
Comment Utility
Thanks. Got it to work. I now know a ton more about namespaces/dlls and how to use them in my webpage.
0
 
LVL 3

Expert Comment

by:cmgarnett
Comment Utility
Here's a  voice from the past for you!

Justin, you seem to be well versed in the ways of dlls and vbc, I was wondering if you cold clarify something for me.

I have been working through some examples in an attempt to get to grips with ASP.NET and have tripped on a fairly early hurdle.

I created a .vb file called database.vb which defined a namespace called database and a public class called database. I compiled this using
"vbc /debug /nologo /t:library /r:System.dll,System.Xml.dll,System.Web.dll,System.Data.dll %1.vb" where parameter %1 = database.vb. I used the resultant .dll in a .aspx web page without any trouble.

The next stage goes on to create a new .vb file called baseclass.vb which must import the earlier database.vb file, and here the fun begins.

Is this the correct way to compile my baseclass.vb file
"vbc /debug /nologo /t:library /imports:%2.dll /r:System.dll,System.Xml.dll,System.Web.dll,System.Data.dll %1.vb" where parameter %1 = baseclass and parameter %2 = database.database?

Any help would be appreciated. I have raised a question which is still awaiting an answer http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21597265.html
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now