RE: Code Behind Page
- From: "Richard" <Richard@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 24 May 2005 14:28:03 -0700
It would be better if you used either a module or a class to put your common
functions. If you use a class, you can declare your methods as Shared so that
you won't have to create an instance of the class to use them. For example, I
have a class of common data routines called SQLDataRoutines, most of which
are shared. Here is a shared function that returns a SQL connection:
Public Shared Function GetConnection(ByVal connectionString As String)
As SqlConnection
Dim connection As New SqlConnection(connectionString)
Try
connection.Open()
Return connection
Catch ex As Exception
Throw ex
End Try
End Function
So behind any of my WebForms I can call it like this:
dim cnn as SQLConnection
dim strConn as String = "Put your connection string here"
cnn = SQLDataRoutines.GetConnection(strConn)
....the rest of your code
Hope this helps.
"Shapper" wrote:
> Hello,
>
> When creating an ASP.NET/VB web site I place my code in a code behind
> page, i.e., aspx.vb.
>
> Sometimes I have functions which are common to all aspx files.
>
> Is it possible in page1.aspx to use page1.aspx.vb and also a common file
> named global.aspx.vb which will hold all the functions common to all
> aspx files in a web site.
>
> How can this be done?
> Should I do it?
>
> Thanks,
> Miguel
>
>
.
- References:
- Code Behind Page
- From: Shapper
- Code Behind Page
- Prev by Date: Re: Any help here???
- Next by Date: Re: CRUD in SP or Dynamic SQL
- Previous by thread: Code Behind Page
- Next by thread: Re: Code Behind Page
- Index(es):
Relevant Pages
|