Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Imports for aspx page that Inherits: Reusing code

Posted on 2004-09-18
7
Medium Priority
?
673 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Accepted Solution

by:
ajitanand earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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