Re: Code Behind Page
- From: "tshad" <tscheiderich@xxxxxxxxxxxxxxx>
- Date: Thu, 2 Jun 2005 09:50:43 -0700
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:u1xS6PXYFHA.3356@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> Could you please post the class code generated by Visual Studio or just
> send it to me by email?
>
> I am using Web Matrix. I consider it simpler to use.
I use DW, myself. I don't like VS2003,either. I am waiting for VS2005 -
which I hear is pretty good.
What I do is create a file (.vb), compile it and move it to my bin file.
Here is a simple one I use:
*******************************************************************
imports System
NameSpace MyFunctions
Public Class BitHandling
'*----------------------------------------------------------*
'* Name : BitSet *
'*----------------------------------------------------------*
'* Purpose : Sets a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitSet(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H80000000 Or Number
Else
Number = (2 ^ Bit) Or Number
End If
BitSet = Number
End Function
'*----------------------------------------------------------*
'* Name : BitClear *
'*----------------------------------------------------------*
'* Purpose : Clears a given Bit in Number *
'*----------------------------------------------------------*
Public Shared Function BitClear(Number As Integer, _
ByVal Bit As Integer) As Long
If Bit = 31 Then
Number = &H7FFFFFFF And Number
Else
Number = ((2 ^ Bit) Xor &HFFFFFFFF) And Number
End If
BitClear = Number
End Function
'*----------------------------------------------------------*
'* Name : BitIsSet *
'*----------------------------------------------------------*
'* Purpose : Test if bit 0 to bit 31 is set *
'*----------------------------------------------------------*
Public Shared Function BitIsSet(ByVal Number As Integer, _
ByVal Bit As Integer) As Boolean
BitIsSet = False
If Bit = 31 Then
If Number And &H80000000 Then BitIsSet = True
Else
If Number And (2 ^ Bit) Then BitIsSet = True
End If
End Function
End Class
End Namespace
*****************************************************************************
I then have a batch file - makeBitHandling.bat
****************************************
vbc /t:library bitHandling.vb /r:system.dll
copy bitHandling.dll bin\*.*
****************************************
In my .aspx page I do the following:
<%@ Import Namespace="MyFunctions" %>
I now can call these routines as:
dim id as integer
id = BitHandling.BitSet(id,4)
You can create many classes in different files and use the same namespace
and you they will all be handled as one. For example, I have another class
that handles my emails using the same namespace. It looks essentially like:
******************************************************************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.SessionState
Imports System.Web.Mail
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports Microsoft.VisualBasic
NameSpace MyFunctions
Public Class Email
Public Shared sub sendEmail ( body as string, emailType as string,
emailTitle as String)
...
end Class
end NameSpace
****************************************************************
I only have to use one import (<%@ Import Namespace="MyFunctions" %>) for
both classes.
Hope that helps,
Tom
>
> Thanks,
> Miguel
>
> "Egghead" <robertlo_NO_SPAM@xxxxxxx> wrote in message
> news:robertlo_NO_SPAM@xxxxxxx:
>
>> I think I will do it in my way :)
>>
>> 1. go to file menu, add a new project ( vb.net or C#), choose
>> ClassLibrary
>> 2. at the solution explorer, left click at the ClassLibrary project,
>> properties, configuration properties, change the output path to your
>> website's bin folder
>> 3. go to the ClassLibrary project, you should c the class, view code, add
>> the function,sub, and a constructor inside the class, build the
>> ClassLibrary.
>> 4. go to your web site project, add the reference, browse to your
>> website's
>> bin folder. You should c the dll file now. add that.
>> 5. in your page's VB.net/C# code, you should be able to do the
>> following,
>> or use the object tag in the asp page (I never try it)
>> dim myclass as ClassLibrary
>> myclass.whatever(whatever)
>> or
>> ClassLibrary myclass = new ClassLibrary();
>> myclass.whatever(whatever)
>>
>> If you want to step into the classlibrary for debugging, go to enable
>> unmanaged debugging and generate debugging information.
>>
>> Egghead
>> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
>> news:%23h4EOVLYFHA.3408@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> > Hello,
>> >
>> > Can you give me a simple example of a file which has a class that
>> > includes 2 functions to be used by all pages in my web site:
>> >
>> > Function Fill_Content(Dim page As String)
>> > End Function
>> >
>> > Sub Build_Menu
>> > End Sub
>> >
>> > And how would I call this class in a page code?
>> >
>> > Thanks,
>> > Miguel
>> >
>> > "Egghead" <robertlo_NO_SPAM@xxxxxxx> wrote in message
>> > news:robertlo_NO_SPAM@xxxxxxx:
>> >
>>
>> > > Why not make a vb.net or C# class holds all your common functions and
>>
>> put it
>>
>> > > in your web site's bin folder?
>> > > Egghead
>> > > "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
>> > > news:OikwySKYFHA.2888@xxxxxxxxxxxxxxxxxxxxxxx
>> > >
>>
>> > > > 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
>> > > >
>>
>> >
>
.
- Prev by Date: Problem with Windows 2003 cluster and ASPNET worker process accounts
- Next by Date: Display Message while code runs.
- Previous by thread: Problem with Windows 2003 cluster and ASPNET worker process accounts
- Next by thread: Display Message while code runs.
- Index(es):
Relevant Pages
|