How can I keep track of a variable scope throughout veveral web pages other than using Sessions
I tried to use Shared member with a module but the problem is that it keeps the session in memory. So if you have 2 browsers open and on a click event in browser 1 you set shared variable stores to "Hello World" then switched to browser 2 the shared variable will have the value of "Hello World"..
Then instead of using a Module I changed it to a Shared property within a class but it resulted in the same bug..
You should try it..
Create a project
Add a Class.vb and call it component and copy and paste this code
Namespace tes
Public Class componen
Private Shared m_strReportName As String = String.Empt
Public Shared Property strReportName() As Strin
Ge
Return m_strReportNam
End Ge
Set(ByVal Value As String
m_strReportName = Valu
End Se
End Propert
End Clas
End Namespac
In you WebForm1.aspx.vb (code behind) copy and paste this
Namespace tes
Public Class WebForm
Inherits System.Web.UI.Pag
#Region " Web Form Designer Generated Code
'This call is required by the Web Form Designer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent(
End Su
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButto
Protected WithEvents LinkButton2 As System.Web.UI.WebControls.LinkButto
'NOTE: The following placeholder declaration is required by the Web Form Designer
'Do not delete or move it
Private designerPlaceholderDeclaration As System.Objec
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Ini
'CODEGEN: This method call is required by the Web Form Designe
'Do not modify it using the code editor
InitializeComponent(
End Su
#End Regio
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
If Not Page.IsPostBack The
If Not component.strReportName = "" The
End I
End I
End Su
Private Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Clic
component.strReportName = "Hello World 1
Response.Write(component.strReportName
End Su
Private Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Clic
Response.Write(component.strReportName
End Su
End Clas
End Namespac
In your WebForm1.aspx html copy and paste the following
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="bugdemo.test.WebForm1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>WebForm1</title><meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"></head><body ms_positioning="GridLayout"><form id="Form1" method="post" runat="server"><asp:linkbutton id="LinkButton1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server">Browser 1 Click This</asp:linkbutton><asp:linkbutton id="LinkButton2" style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 32px
runat="server">Browser 2 Click This</asp:linkbutton></form></body></html
Now open two browsers and follow instructions... You will see that when you click on the link "Browser 2 Click This" in browser two the value of strReportName should have been empty instead it contains the value of strReportName set in browser 1
So my question is how can I resolve this problem
Yama Kamya
----- vMike wrote: ----
Maybe this will help
Modules are a reference type similar to classes, but with some importan
distinctions. The members of a module are implicitly Shared and scoped to
the declaration space of the standard module's containing namespace, rather
than just to the module itself. Unlike classes, modules can never be
instantiated, do not support inheritance, and cannot implement interfaces.
"Yama" <an*******@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
Hi, Actually the component code should be:
myModule.vb code: Namespace FinancialCompany.Portal
Public Module myModule
Public Class myProperties
Private _intCounter As System.Int32 Public Property intCounter() As System.Int32
Get
Return _intCounter
End Get
Set(ByVal Value As System.Int32)
_intCounter = Value
End Set
End Property
End Classs
End Module
End Namespace default.aspx code:
Imports FinancialCompany.Portal.myModule.myProperties Namespace FinancialCompany.Portal
Public Class _default
Inherits System.Web.UI.Page Private m_test As System.Int32 = Request.QueryString("TEST")
Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter += 2 Response.Write("Here is the result: " + CStr(m_test)) End If
End Sub
End Class
End Namespace Yama Kamyar
----- Yama wrote: -----
Hello All,
I have developed a new site using ASP.NET/VB.NET. I fell into a big
problem. Here is the problem: I created a module as follow:
Namespace FinancialCompany.Portal
Public Class myProperties
Private _intCounter As System.Int32 Public Property intCounter() As System.Int32
Get
Return _intCounter
End Get
Set(ByVal Value As System.Int32)
_intCounter = Value
End Set
End Property
End Classs
End Namespace Now I use this in an ASP.NET page as follow:
Imports FinancialCompany.Portal.myProperties
Namespace FinancialCompany.Portal
Public Class _default
Inherits System.Web.UI.Page Private m_test As System.Int32 = Resquest.QueryString("TEST")
Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) If Not Page.IsPostback Then
If m_test = 0 Then intCounter += 0
If m_test = 1 Then intCounter += 1
If m_test = 2 Then intCounter += 2 Response.Write("Here is the result: " + CStr(m_test))
End If
End Sub
End Class
End Namespace Now when I tested this with two to five users with the following
URLs: User 1: http://localhost/myproject/default.aspx?TEST=0
User 2: http://localhost/myproject/default.aspx?TEST=1
User 3: http://localhost/myproject/default.aspx?TEST=2 If user 2 clicks the URL he gets:
Here is the result: 1 But if user 3 cllicks the URL he gets:
Here is the result: 3
instead of:
Here is the result: 2 Hence the intCount property remains active for every users!!! I
expect it to be a different instance for each different users. How come is it being shared???
I am using Windows 2000 Server, ASP.NET 2003, & Framework 1.1
Hope someone can help me... Should I simply just use
Session("intCount") instead or even Application("intCounter")? I really need to understand why the hack is intCounter being stored
in memory... Thanks,
Yama