Solved

Imports for aspx page that Inherits: Reusing code

Posted on 2004-09-18
7
666 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
ID: 12093934
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
ID: 12094228
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
ID: 12094437
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Accepted Solution

by:
ajitanand earned 500 total points
ID: 12094484
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
ID: 12096121
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
ID: 12097713
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
ID: 15152395
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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