Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to share VB code across multiple pages?

Reply
Thread Tools

How to share VB code across multiple pages?

 
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      09-28-2005
I am new to .NET framework.

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!

 
Reply With Quote
 
 
 
 
darrel
Guest
Posts: n/a
 
      09-28-2005
> 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


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      09-28-2005
> 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!


ASP.Net is fully-compiled and object-oriented. So, one of the first things
you need to do as a new ASP.Net programmer is to retrain your thinking.
There are no pages in an ASP.Net application. There are only classes. A
System.Web.UI.Page is a class, and that template you create is just part of
the class definition.

So, you don't ever define Subs in files. They are methods in classes.

Now, the reason I'm sayiing this is that you need to create a class that
contains your common Subs, and use that in all of your Page classes. It
doesn't have direct access to the HttpContext that is passed to a page, but
remember that it will be used BY a Page, which does have the HttpContext.
And you can reference it in your class thusly:

' Using Request as a part of the HttpContext
Public Sub DoSomething()
Dim Request As HttpRequest = CType(HttpContext.Current.Handler,
System.Web.UI.Page).Request
If Request.QueryString("SomeParameter") = "foo" Then
'Do Something
End If
End Sub

It will really help you to reflect on the Object-oriented nature of .Net, in
order to leverage it to its fullest extent.

HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I am new to .NET framework.
>
> 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!
>



 
Reply With Quote
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      09-28-2005
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


 
Reply With Quote
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      09-28-2005
Thanks, Kevin, I was a Java programmer. So I think that I know a little
bit about OO programming. It is a new thing to me that .Net framwork
does not have a page. Because of this, I am kinda confused by the
sample code your provided.

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      09-28-2005
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/
======================================
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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

>



 
Reply With Quote
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      09-29-2005
Hi, Juan,

Yes, I am using ASP.NET 1.1. I tried compiling MyClass.vb using
vbc.exe, but got an error message as follows:

"The application has failed to start because MSVCR71.dll was not
found.Reinstalling this application may fix this problem"

But MSVCR71.dll is actually right there under the folder
Windows\Microsoft.NET\Framework\v1.1.4322. How to fix this please?

By the way, how to get ASP.NET 2.0? Is it freely upgradable?


Juan T. Llibre wrote:
> 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/
> ======================================
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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

> >


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      09-29-2005
re:
>I tried compiling MyClass.vb using vbc.exe, but got an error message


Was your compilation attempt made from a directory
included in your system's environment path ?

It could also be that you have a failed .Net Framework install.
Uninstalling and reinstalling the .Net framework would help in that case.

re:
>how to get ASP.NET 2.0? Is it freely upgradable?


If you are an MSDN subscriber,you can download the RC at :
http://lab.msdn.microsoft.com/vs2005/get/default.aspx

Otherwise, you can download the public 2.0 Beta versions here :
http://lab.msdn.microsoft.com/vs2005/get/default.aspx

Also, there's a download which includes the
Beta 2 Visual Web Developer version at :

http://lab.msdn.microsoft.com/express/vwd/default.aspx




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/
======================================
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
Hi, Juan,

Yes, I am using ASP.NET 1.1. I tried compiling MyClass.vb using
vbc.exe, but got an error message as follows:

"The application has failed to start because MSVCR71.dll was not
found.Reinstalling this application may fix this problem"

But MSVCR71.dll is actually right there under the folder
Windows\Microsoft.NET\Framework\v1.1.4322. How to fix this please?

By the way, how to get ASP.NET 2.0? Is it freely upgradable?


Juan T. Llibre wrote:
> 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/
> ======================================
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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

> >



 
Reply With Quote
 
antonyliu2002@yahoo.com
Guest
Posts: n/a
 
      09-29-2005
Hi, Juan,

Yes, I've set the PATH variable. But I am still getting that error
message.

That said, I have downloaded and installed the ASP.20 Visual Web
Developer kit and issued aspnet_regiis.exe -i.

Now, when I check out my web application, I get this error message:

******************************************
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a
Web Farm or cluster, ensure that <machineKey> configuration specifies
the same validationKey and validation algorithm. AutoGenerate cannot be
used in a cluster.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Validation of viewstate
MAC failed. If this application is hosted by a Web Farm or cluster,
ensure that <machineKey> configuration specifies the same validationKey
and validation algorithm. AutoGenerate cannot be used in a cluster.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
******************************************




Juan T. Llibre wrote:
> re:
> >I tried compiling MyClass.vb using vbc.exe, but got an error message

>
> Was your compilation attempt made from a directory
> included in your system's environment path ?
>
> It could also be that you have a failed .Net Framework install.
> Uninstalling and reinstalling the .Net framework would help in that case.
>
> re:
> >how to get ASP.NET 2.0? Is it freely upgradable?

>
> If you are an MSDN subscriber,you can download the RC at :
> http://lab.msdn.microsoft.com/vs2005/get/default.aspx
>
> Otherwise, you can download the public 2.0 Beta versions here :
> http://lab.msdn.microsoft.com/vs2005/get/default.aspx
>
> Also, there's a download which includes the
> Beta 2 Visual Web Developer version at :
>
> http://lab.msdn.microsoft.com/express/vwd/default.aspx
>
>
>
>
> 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/
> ======================================
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> Hi, Juan,
>
> Yes, I am using ASP.NET 1.1. I tried compiling MyClass.vb using
> vbc.exe, but got an error message as follows:
>
> "The application has failed to start because MSVCR71.dll was not
> found.Reinstalling this application may fix this problem"
>
> But MSVCR71.dll is actually right there under the folder
> Windows\Microsoft.NET\Framework\v1.1.4322. How to fix this please?
>
> By the way, how to get ASP.NET 2.0? Is it freely upgradable?
>
>
> Juan T. Llibre wrote:
> > 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/
> > ======================================
> > <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> > > 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, Iput
> > >> > the Subs in each individual page.
> > >> >
> > >> > I think there must be a way to save my Subs in a separate file andthen
> > >> > 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
> > >


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      09-29-2005
re:
> That said, I have downloaded and installed the ASP.20
> Visual Web Developer kit and issued aspnet_regiis.exe -i.


From which .Net Framework directory ?

From the 1.1 .Net Framework dir, or from the 2.0 directory ?

Also, did you change your application's directory so it runs
the 2.0 ASP.NET version, or is it still running the 1.1 version ?

If the ASP.NET tab is available in the IIS Manager, change
the target .Net Framework version to the appropiate one.

If it's not available, download Denis Bauer's ASP.NET Version Switcher
and change the ASP.NET version for you app withj that :

http://www.denisbauer.com/NETTools/A...nSwitcher.aspx

Remember that now that you're running two versions of ASP.NET that,
at least, all 1.1 apps will need to be in one AppPool and all 2.0 apps
will need to be in a different AppPool.




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/
======================================
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
Hi, Juan,

Yes, I've set the PATH variable. But I am still getting that error
message.

That said, I have downloaded and installed the ASP.20 Visual Web
Developer kit and issued aspnet_regiis.exe -i.

Now, when I check out my web application, I get this error message:

******************************************
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a
Web Farm or cluster, ensure that <machineKey> configuration specifies
the same validationKey and validation algorithm. AutoGenerate cannot be
used in a cluster.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Validation of viewstate
MAC failed. If this application is hosted by a Web Farm or cluster,
ensure that <machineKey> configuration specifies the same validationKey
and validation algorithm. AutoGenerate cannot be used in a cluster.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
******************************************




Juan T. Llibre wrote:
> re:
> >I tried compiling MyClass.vb using vbc.exe, but got an error message

>
> Was your compilation attempt made from a directory
> included in your system's environment path ?
>
> It could also be that you have a failed .Net Framework install.
> Uninstalling and reinstalling the .Net framework would help in that case.
>
> re:
> >how to get ASP.NET 2.0? Is it freely upgradable?

>
> If you are an MSDN subscriber,you can download the RC at :
> http://lab.msdn.microsoft.com/vs2005/get/default.aspx
>
> Otherwise, you can download the public 2.0 Beta versions here :
> http://lab.msdn.microsoft.com/vs2005/get/default.aspx
>
> Also, there's a download which includes the
> Beta 2 Visual Web Developer version at :
>
> http://lab.msdn.microsoft.com/express/vwd/default.aspx
>
>
>
>
> 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/
> ======================================
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> Hi, Juan,
>
> Yes, I am using ASP.NET 1.1. I tried compiling MyClass.vb using
> vbc.exe, but got an error message as follows:
>
> "The application has failed to start because MSVCR71.dll was not
> found.Reinstalling this application may fix this problem"
>
> But MSVCR71.dll is actually right there under the folder
> Windows\Microsoft.NET\Framework\v1.1.4322. How to fix this please?
>
> By the way, how to get ASP.NET 2.0? Is it freely upgradable?
>
>
> Juan T. Llibre wrote:
> > 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/
> > ======================================
> > <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> > > 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
> > >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
J2EE - How to share tomcat sessions across multiple IE windows Adam Lipscombe Java 8 10-24-2007 04:39 PM
Share VB code across multiple pages? antonyliu2002@yahoo.com ASP .Net 6 11-19-2005 12:20 PM
Share games across network =?Utf-8?B?S2VpdGg=?= Wireless Networking 1 08-29-2005 06:30 PM
Best Practice: How to share an ASP.NET webform across multiple web apps: Jheitmuller ASP .Net 1 08-02-2004 10:56 PM



Advertisments