Dear All,
To confirm that I understand the discussion, modules in VB.NET are static and variables declared in modules are shared between all sessions of a WebGui application (i.e. all instances of a WebGui application). And because static means global, this implies that a property or variable declared as Public in a module will be allocated one memory slot on the Web Server.
For example, a WebGui application has a public (i.e. global) variable declared in a module. When the first session of that WebGui application starts, the Web Server will allocate memory for that global variable. When the next session of that WebGui application starts, it will access the global variable stored in that memory slot. The Web Server will NOT create a second memory slot for global variable. Thus, both WebGui sessions will be accessing the same memory slot or public variable.
So if I want to create Constants that are shared across all WebGui sessions, I could create a module as follows:
Module modGlobalConstants
'Column States
Friend Const blnBoundToDataSource As Boolean = True
Friend Const blnBoundToDataSourceNot As Boolean = False
Friend Const blnFrozen As Boolean = True
Friend Const blnFrozenNot As Boolean = False
Friend Const blnReadOnly As Boolean = True
Friend Const blnReadOnlyNot As Boolean = False
Friend Const blnVisible As Boolean = True
Friend Const blnVisibleNot As Boolean = False
End Module
Or if want to create a procedure that is shared across all WebGui sessions, I could create a module as follows:
Module modGlobalSubs
Friend Sub PopulateCountryDGVComboBox( _
ByRef CountryComboBox As Gizmox.WebGUI.Forms.DataGridViewComboBoxColumn _
, ByRef dbConn As SqlConnection _
)
Dim cmd As New SqlCommand("sp_COUNTRY_Select", dbConn)
cmd.CommandType = CommandType.StoredProcedure
Dim dr As SqlDataReader = cmd.ExecuteReader()
With CountryComboBox
While dr.Read()
.Items.Add(dr("COUNTRY_NAME"))
End While
End With
dr.Close()
cmd.Dispose()
End Sub
End Module
Or, if I want to store the Vendor Name for each session, I want to either store the Vendor Name in a session variable as follows:
Context.Session.Item("VendorName") = VendorName
Or as an alternative approach, I could create a class called GlobalProperties and use Get and Set to store the value as shown below
Public Class clsGlobalProperties
Public Property VendorName() As String
Get
Return VWGContext.Current(“VendorName”)
End Get
Set(ByVal value As String)
VWGContext.Current(“VendorName”) = value
End Set
End Property
End Class
Then, I would instantiate the class in each form as illustrated below:
Private GP As New clsGlobalProperties
Dim VendorName As String = GP.VendorName
However, I would NOT want to store the Vendor Name in a property defined in a module such as shown below because each WebGui session will reference the same memory slot on the Web Server:
Module modGlobalProperties
Private _VendorName As String
Public Property VendorName() As String
Get
Return _VendorName
End Get
Set(ByVal value As String)
VendorName = value
End Set
End Property
End Module
In other words, each WebGui session does NOT create its own instance of the above module.
Have I correctly understood the discussion? If not, please correct me.
Thanks!