Share VB code across multiple pages?

A

antonyliu2002

I am using ASP.NET 1.1.

In my web application, multiple pages will be using the same functions.
I am wondering if I can just pick out the shared code and save it in a
separate file and then imports it in my webpages.

Say if I save my VB functions in a file called mySharedCode.vb which
has for example a Sub called "ConvertTextBoxData", how do I call this
Sub in my page called page1.aspx?

Thanks a lot!
 
J

Juan T. Llibre

re:
how do I call this Sub in my page called page1.aspx?

You don't.

What you do is compile "SharedCode.vb" to an assembly,
place the assembly in the /bin directory, and import your class's
namespace into any aspx page you want to use it in.

vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll

If you need to add more .net classes, add them like this:
/r:system.dll /r:system.data.dll /r:system.xml.dll

Then, import your namespace into your aspx page :

<%@ Import Namespace="SharedCode" %>

This assumes that your class's namespace is named SharedCode.
 
A

antonyliu2002

OK. thanks. But it's like pain in the butt for me to compile my VB
code. When I tried doing that before, the system keeps saying that
this library is missing, that dll file is not found.
 
J

Juan T. Llibre

You have to know which assemblies you need to call.

Just add any required .net assemblies:

vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll /r:system.data.dll

etc.

If it's a pain in the butt, you're doing it the wrong way... ;-)
It's quite easy, actually.

Use the class browser to find out what's where.
 
P

Patrick.O.Ige

Juan can VS.NET do this for you?
Patrick

Juan T. Llibre said:
You have to know which assemblies you need to call.

Just add any required .net assemblies:

vbc /t:library /out:..\bin\SharedCode.dll SharedCode.vb /r:system.dll /r:system.data.dll

etc.

If it's a pain in the butt, you're doing it the wrong way... ;-)
It's quite easy, actually.

Use the class browser to find out what's where.
 
J

Juan T. Llibre

No.

VS.NET 2005 has a feature which could be useful,
which is placing class files in the App_Code directory.

They get compiled automatically, and can be referenced
in aspx pages, but that's not quite the same.

The ability to compile assemblies from the command-line is
one of the most powerful features the .Net Framework offers.

It makes the job of creating classes, and referencing them in aspx pages, a snap.

After they're compiled, adding a reference to them in VS.NET
lets you access all the classes, methods and properties with full intellisense.
 
P

Patrick.O.Ige

Thx Juan
Awesome Juan.
Good Good.
Reading through some books for ASPNET 2.0 for now.
But will get my hands on it soon
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top