Re: How to share VB code across multiple pages?



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

  • Re: Class Reference Problem
    ... solution and also added a reference to the ... "Chris Smith" wrote: ... > Public Class Test ... > Public Sub Testsub() ...
    (microsoft.public.dotnet.languages.vb)
  • RE: About Creating Objects Dynamically
    ... a reference to that project in the references section of the solution tree ... Public Class GetThis ... Public Sub GetThisMessage ... > Public Function SendMsg() ...
    (microsoft.public.dotnet.languages.vb)
  • Re: how do you implement association between objects
    ... Private Sub Button1_Click(ByVal sender As Object, ... Public Class Class1 ... CarA is a member of the Form. ... If you want to access CarA, you need a reference to the Form that contains CarA. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Project reference problem
    ... Go to your class1 project, Add Reference, go to the Projects Tab, ... > Public Class Class1 ... > Public Sub New ...
    (microsoft.public.dotnet.languages.vb)
  • Re: An absence of IntelliSense in this situation
    ... > event source and only need to know if and when it fires an event then ... > Public Class CBaseEventSourceContainer ... > End Sub ... >>> As you say you still have access to the base class event source ...
    (microsoft.public.dotnet.languages.vb)

Loading