I have a web application that instanciate a Business Rules Object (once and keep it alive in session). That's object raise an event if some data need to me refresh to the interface. (Event=OnChange). My problem is that when the event occure everything
work fine, but when I postback my page again the same event is still there and my page receive it like a new one. And if my rule send me back another OnChange event, my page will receive 2 events, event if there is only one asked.
If I browse to another page, and that page handle the OnChange event i'll have 2 events like the other.
You should try it to really understand!! See example below...
So that's my problem!! I didn't expect that it will work like this at all and I don't want to! Do you have any idea of the reason of my problem??
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents lblCNTRULE As System.Web.UI.WebControls.Label
Protected WithEvents lblCNTEVENT As System.Web.UI.WebControls.Label
Protected WithEvents lblCNTRULEValue As System.Web.UI.WebControls.Label
Protected WithEvents lblCNTEVENTValue As System.Web.UI.WebControls.Label
Protected WithEvents btnAction As System.Web.UI.WebControls.Button
Protected WithEvents btnDummy As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public Class Rules
Public Event OnChange()
Public m_iCNT As Integer = 0
Public Sub Action()
m_iCNT += 1
RaiseEvent OnChange()
End Sub
End Class
Private WithEvents m_RulesObject As Rules
Private ReadOnly Property RulesObject() As Rules
Get
If m_RulesObject Is Nothing Then
Dim l_obj As Object = Session.Item("RulesObject")
If l_obj Is Nothing Then
m_RulesObject = New Rules
Session.Item("RulesObject") = m_RulesObject
Else
m_RulesObject = CType(l_obj, Rules)
End If
End If
Return m_RulesObject
End Get
End Property
Private Property CNTEVENTValue() As Integer
Get
Dim l_obj As Object = Session.Item("CNTEVENTValue")
If l_obj Is Nothing Then
Me.CNTEVENTValue = 0
Return Me.CNTEVENTValue
Else
Return CInt(l_obj)
End If
End Get
Set(ByVal Value As Integer)
Session.Item("CNTEVENTValue") = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Bind()
End Sub
Private Sub Bind()
lblCNTRULEValue.Text = RulesObject.m_iCNT.ToString
lblCNTEVENTValue.Text = CNTEVENTValue.ToString
End Sub
Private Sub btnAction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAction.Click
RulesObject.Action()
End Sub
Private Sub m_RulesObject_OnChange() Handles m_RulesObject.OnChange
' do some tasks
CNTEVENTValue += 1
Bind()
End Sub
Simon Norman...
Member
10 Points
2 Posts
Problem with event generation
Jul 03, 2006 02:16 PM|LINK
Hi,
I have a web application that instanciate a Business Rules Object (once and keep it alive in session). That's object raise an event if some data need to me refresh to the interface. (Event=OnChange). My problem is that when the event occure everything work fine, but when I postback my page again the same event is still there and my page receive it like a new one. And if my rule send me back another OnChange event, my page will receive 2 events, event if there is only one asked.
If I browse to another page, and that page handle the OnChange event i'll have 2 events like the other.
You should try it to really understand!! See example below...
So that's my problem!! I didn't expect that it will work like this at all and I don't want to! Do you have any idea of the reason of my problem??
Thank's for your help!
Simon
Example:
</div><%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="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="VBScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table border="0">
<tr>
<td>
<asp:Label id="lblCNTRULE" runat="server">Nb of call to Rules.Action()</asp:Label></td>
<td>
<asp:Label id="lblCNTRULEValue" runat="server">0</asp:Label></td>
</tr>
<tr>
<td>
<asp:Label id="lblCNTEVENT" runat="server">Nb of Rules.OnChange() Event</asp:Label></td>
<td>
<asp:Label id="lblCNTEVENTValue" runat="server">0</asp:Label></td>
</tr>
</table>
<asp:Button id="btnAction" runat="server" Text="Action"></asp:Button>
<asp:Button id="btnDummy" runat="server" Text="Simple Post"></asp:Button>
</form>
</body>
</HTML>
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents lblCNTRULE As System.Web.UI.WebControls.Label
Protected WithEvents lblCNTEVENT As System.Web.UI.WebControls.Label
Protected WithEvents lblCNTRULEValue As System.Web.UI.WebControls.Label
Protected WithEvents lblCNTEVENTValue As System.Web.UI.WebControls.Label
Protected WithEvents btnAction As System.Web.UI.WebControls.Button
Protected WithEvents btnDummy As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public Class Rules
Public Event OnChange()
Public m_iCNT As Integer = 0
Public Sub Action()
m_iCNT += 1
RaiseEvent OnChange()
End Sub
End Class
Private WithEvents m_RulesObject As Rules
Private ReadOnly Property RulesObject() As Rules
Get
If m_RulesObject Is Nothing Then
Dim l_obj As Object = Session.Item("RulesObject")
If l_obj Is Nothing Then
m_RulesObject = New Rules
Session.Item("RulesObject") = m_RulesObject
Else
m_RulesObject = CType(l_obj, Rules)
End If
End If
Return m_RulesObject
End Get
End Property
Private Property CNTEVENTValue() As Integer
Get
Dim l_obj As Object = Session.Item("CNTEVENTValue")
If l_obj Is Nothing Then
Me.CNTEVENTValue = 0
Return Me.CNTEVENTValue
Else
Return CInt(l_obj)
End If
End Get
Set(ByVal Value As Integer)
Session.Item("CNTEVENTValue") = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Bind()
End Sub
Private Sub Bind()
lblCNTRULEValue.Text = RulesObject.m_iCNT.ToString
lblCNTEVENTValue.Text = CNTEVENTValue.ToString
End Sub
Private Sub btnAction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAction.Click
RulesObject.Action()
End Sub
Private Sub m_RulesObject_OnChange() Handles m_RulesObject.OnChange
' do some tasks
CNTEVENTValue += 1
Bind()
End Sub
End Class