RE: Code Behind Page



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
>
>
.



Relevant Pages

  • PRE-PEP: new Path class
    ... Should path be a subclass of str? ... be times a developer wants to use string methods, ... the most common operations should be supported directly. ... to divide (separate) things. ...
    (comp.lang.python)
  • Re: Is there a Function and Function Argument generic self-reference?
    ... Private Class Common ... Public Overridable Function As String ... Sub Stored_Procedure_Common(ByVal Command As DB2Command) ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Userform to obtain folder (path) info ?
    ... You can modify the Common dialog control to open up as a browse folder ... ByVal lpBuffer As String) As Long ... Dim lpIDList As Long ...
    (microsoft.public.word.vba.userforms)
  • How display Windows dialog to get a file destination?
    ... documented how to call the Open common Dialog box. ... '* Created by Microsoft ... Public Function GetOpenFile(strInitialDir As String, ... Dim typWinOpen As API_WINOPENFILENAME ...
    (microsoft.public.access.formscoding)
  • Re: Common Dialog questions
    ... Private Const MAX_LENGTH = 260 ... Private Function GetFolderPathAs String ... There's also a way to directly set the directory in the common dialog by ... the virtual desktop folder and not that of the file system, ...
    (microsoft.public.vb.winapi)