Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Function Modules, @ASSEMBLY or @REGISTER?


Message #1 by "Adrian Inman" <adrian@f...> on Sat, 8 Jun 2002 11:49:46
Adrian,

	You should be using code behind files (that is, your source code
isn't intermixed with the HTML at all), and with this you can mix standard
*.vb or *.cs classes as long as you compile them into the assembly.  Take
for example the following class (I have no idea how namespaces appear in VB
BTW):

' assume the namespace is Example.Data
Public Shared Function GetData (sql As String) _
	As System.Data.OleDbDataReader
	' note naming conventions in MSDN
	' ...
	Return dr
End Function

	Now anywhere in your code behind files you could be doing:

Dim dr As OleDbDataReader = Example.Data.GetData(sql)

or even:

Dim dr As OleDbDataReader = GetData(sql)

if you include the namespace in the code behind file (I have no idea how
this is done with VB).

	However, before you go rampant with modular coding practices, take a
few moments to plan out your design and try to take an OOP approach instead.
You'll find that your code will be a much more elegant solution and easier
to manage and maintain.

	As a final note, this being ASP.NET and all, its worth it to mention
that System.Web.HttpContext.Current will give you access to the Session,
Application, Cache collections and Request and Response objects of the
current HTTP request being handled by aspnet_wp.exe so you don't need to
work any black magic to access stuff in ASP.NET.

HTH,
- Chuck
	

-----Original Message-----
From: Adrian Inman [mailto:adrian@f...]
Sent: Saturday, June 08, 2002 7:50 AM
To: ASPX_Professional
Subject: [aspx_professional] Function Modules, @ASSEMBLY or @REGISTER?


I used to use custom written functions a lot in my asp work like a 
function called getFieldContents(pSQL, pFieldname) which would 
get the contents of a field by executing some short code.
This and many other functions were made available to my code 
using includes (I know I could have used components!).
ASP.Net is here and I want to achieve the same sort of effect, but 
don't know how.

I'm doing it in VB.NET as the page language, so no C# please.
I am aware of the bin directory and the @ASSEMBLY directive but my 
lovely professional asp.net 1.0 book doesn't seem to have any info 
on this sort of thing.

Can someone please give me some pointers as this is a very useful 
thing I'm trying to do.

Thanks in advance, Adrian

  Return to Index