Share VB code across multiple pages?

  • Thread starter Thread starter antonyliu2002
  • Start date Start date
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!
 
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.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 
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.
 
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.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 
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.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 
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.




Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 
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
 
Back
Top