Solved

Imports for aspx page that Inherits: Reusing code

Posted on 2004-09-18
7
667 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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