473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sub Routine for whole site

I'm a newbie. I'm using VS2008 & VB.net
I have a simple site and each page uses the same sub-routine. I copy and
paste to each page and that's no big deal but that can get tiresome. I was
wondering if it's possible to create a MASTER sub routine where all the
pages can call it and perform it's task for that page. If so, where would I
create something like that in VS2008?

Thanks!
Phil
Jun 27 '08 #1
2 1435
re:
!I was wondering if it's possible to create a MASTER sub routine
!where all the pages can call it and perform it's task for that page.

Wonder no more.

There's 2 solutions to that problem :

1. Create a helper class in your application's App_Code directory.
( anyName.cs or anyName.vb )

You can now call your master routine from any page.

2. Create a helper class ( anyName.cs or anyName.vb ), compile the class
to an assembly, and place the assembly in the /bin directory of your application.

vbc /t:library /out:anyName.dll anyName.vb

anyName.dll will be created/compiled in the current directory.

Move the assembly to the /bin directory of your application and fire away.
If you want to have VS.NET use it, reference it in your project.

If you want to use C#, then the command line would be :

csc /t:library /out:anyName.dll anyName.cs

If you need to import .Net classes, include them in your command line:

vbc /t:library /r:system.dll /r:system.web.dll /out:anyName.dll anyName.vb
or
csc /t:library /r:system.data.dll /r:system.web.dll /out:anyName.dll anyName.cs

After that, you can import the namespace into any page with :

<%@ Import Namespace="YourClassname" %>

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/
======================================
"pvong" <phillip*at*yahoo*dot*comwrote in message news:e1**************@TK2MSFTNGP04.phx.gbl...
I'm a newbie. I'm using VS2008 & VB.net
I have a simple site and each page uses the same sub-routine. I copy and paste to each page and that's no big deal
but that can get tiresome. I was wondering if it's possible to create a MASTER sub routine where all the pages can
call it and perform it's task for that page. If so, where would I create something like that in VS2008?

Thanks!
Phil


Jun 27 '08 #2
Jaun, thanks for replying but I'm still a little confused. Let me break it
down a little more. I'm only programming in VB.net for and asp.net page.

1)------This is my sub routine------
Sub CkKeyID()
Dim KeyID As String = Request.QueryString("KeyID").ToString
If Not Session("ClientID").ToString = KeyID Then
Server.Transfer("/KeyIdError.aspx")
End If
End Sub
------------------
As you can see, all it's doing is checking to see if my sessionID is = to
KeyID

2) I created a KeySub.vb in App_Code and I pasted this code in. When I do
that, I get "Not Declared" for request, session and server. What should I
put in her to replicated this sub routine?

3)I pretended the code works for KeySub.vb in App_Code and I imported the
class at the top of the page. Once I do that, how do I call the sub
routine? I usually type just the sub routine name it works but when I type
CkKeyID(), but that did not work. I tried KeyIdSub.Equals("CkKeyID") but I
get the error msg "Reference to a non-shared member requires an object
reference."

Basically, what do I have to put in the KeyIdSub.vb to re-create my sub
routine and how do I call it from an aspx page?

Thanks for helping.

Phil
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:O4**************@TK2MSFTNGP03.phx.gbl...
re:
!I was wondering if it's possible to create a MASTER sub routine
!where all the pages can call it and perform it's task for that page.

Wonder no more.

There's 2 solutions to that problem :

1. Create a helper class in your application's App_Code directory.
( anyName.cs or anyName.vb )

You can now call your master routine from any page.

2. Create a helper class ( anyName.cs or anyName.vb ), compile the class
to an assembly, and place the assembly in the /bin directory of your
application.

vbc /t:library /out:anyName.dll anyName.vb

anyName.dll will be created/compiled in the current directory.

Move the assembly to the /bin directory of your application and fire away.
If you want to have VS.NET use it, reference it in your project.

If you want to use C#, then the command line would be :

csc /t:library /out:anyName.dll anyName.cs

If you need to import .Net classes, include them in your command line:

vbc /t:library /r:system.dll /r:system.web.dll /out:anyName.dll anyName.vb
or
csc /t:library /r:system.data.dll /r:system.web.dll /out:anyName.dll
anyName.cs

After that, you can import the namespace into any page with :

<%@ Import Namespace="YourClassname" %>

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/
======================================
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:e1**************@TK2MSFTNGP04.phx.gbl...
>I'm a newbie. I'm using VS2008 & VB.net
I have a simple site and each page uses the same sub-routine. I copy and
paste to each page and that's no big deal
but that can get tiresome. I was wondering if it's possible to create a
MASTER sub routine where all the pages can
call it and perform it's task for that page. If so, where would I create
something like that in VS2008?

Thanks!
Phil



Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Caliangelas | last post by:
Hello, I need a routine to check for a number called CPF (just like Social Security Number in USA). I already have a validation routine for that number, but I still need to check if it exists on...
10
by: Papa.Legba.666 | last post by:
There are many good HTML validators, not least, of course being w3c's. However, they only handle one page at a time. Is there a free web based served, or pc program, which will crawl my site...
4
by: Paul Brown | last post by:
Thanks for the replies Tristan, Eric, Steven & Kurt. They have given me some good leads. I present justification for a lot of the comments that drew (constructive) criticism below. Firstly, let...
0
by: Roger Twomey | last post by:
I am writing a Windows service which is run (and tested) at a remote location so I cannot debug issues at the actual deployment site. I know that the application is having some sort of trouble as...
3
by: willwade | last post by:
Hi there, Sorry for the perhaps undirected post - Ive struggled for the past few hours and cant see the wood for the trees.. I have a page (infact a site but I will keep it simple) that is a...
2
by: \A_Michigan_User\ | last post by:
*WITHOUT* using: ValidateRequest="False" for the whole page (or my whole site).... How would I trap/detect that a textBox contains some illegal characters? (I'm using asp.net v1.1 and vb.net)...
2
by: billkirim | last post by:
i am using this code to preload my site: <script type="text/javascript"> document.write('<div id="loading"><br><br>The musicase is Loading...</div>'); window.onload=function(){ ...
4
by: Darin | last post by:
I have a public class that I use to read columns out of a SQL database. In the try, catch, loop I want to display the error, and in the error I want to display the calling routine (and helpfully...
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.