Re: How to share VB code across multiple pages?



If you're using ASP.NET 2.0, place MyClass.vb
in the App_Code folder. You'll be able to access it there.

If you're using ASP.NET 1.1, you should command-line compile
MyClass.vb to MyClass.dll and place it in the /bin drectory.

You, then, can import the namespace in your aspx file with :
<%@ Import Namespace="YourNameSpaceName" %>
and instantiate your classes from any aspx page.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
<antonyliu2002@xxxxxxxxx> wrote in message
news:1127931941.719998.234850@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi, Thx.
>
> After I got your reply, then I created a file called "MyClass.vb" in
> the same folder of the webpages.
>
> MyClass.vb has a Class like this:
>
> Public Class MyClass
> Public Sub MySub()
> Do Something
> End Sub
> End Class
>
> I called the MySub like this in my webpage:
>
> Call MyClass.MySub()
>
> This is the compile error:
>
> BC30456: 'MySub' is not a member of 'ASP.Page1_aspx'.
>
> Apparently I did not do it in the right way. I think I am doing it
> like Java. I was a Java programmer.
>
> Shouldn't I tell Page1.aspx where to find that function?
>
> darrel wrote:
>> > A bunch of web pages of mine need the same function. Right now, I put
>> > the Subs in each individual page.
>> >
>> > I think there must be a way to save my Subs in a separate file and then
>> > have each web page link to it. Could you guys please let me know how
>> > to do this? Thanks a lot!
>>
>> There are a variety of ways. One way is to just make a new class file (a .vb
>> or .cs file) and then reference the function that way.
>>
>> I typically make a new class file called sharedFunctions and then put
>> specific functions within it. I can then reference them from any file in the
>> project: sharedFunctions.myFunction()
>>
>> -Darrel
>


.



Relevant Pages


Loading