By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

An "All the time" event?

P: n/a
Is there any way to add some code that will happen in every single Event
that i raised in a form?

I have a Total field in the bottom of a pretty complex page and I think it's
kind of "Dirty" to update that Filed from every single Event that might
affect it

Is there are was to keep that Filed Total (a value) updated at all time
without having to think about it in every single event on the page?

Nomatter what happens and what fileds are updated on the page.. in a grid or
in another filed, I want that Total filed to be Updated...

/Lars
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Nope.

couple reasons.

1) Thats a lot of friggin events

2) Each event has its own signature. While many are the same, there are
many that are different. No "universal" event handler.

3) Not that many events fire on an ASP.NET page at once... Usually, 1...

4) If you want to catch something each time it happens in ASP.NET the
Page.Load event is always the first one fired, and you can validate whether
its a postback or not.

5) Look into storing values in the viewstate... or the session object.

hope it helps.

-CJ

"Lars Netzel" <[no_spam_please]la*********@qlogic.se> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
Is there any way to add some code that will happen in every single Event
that i raised in a form?

I have a Total field in the bottom of a pretty complex page and I think it's kind of "Dirty" to update that Filed from every single Event that might
affect it

Is there are was to keep that Filed Total (a value) updated at all time
without having to think about it in every single event on the page?

Nomatter what happens and what fileds are updated on the page.. in a grid or in another filed, I want that Total filed to be Updated...

/Lars

Nov 20 '05 #2

P: n/a
You could try hooking up all your controls Leave Events or Validating Events
(if you aren't using them for something else) to one event handler and call
your update form there.
"Lars Netzel" <[no_spam_please]la*********@qlogic.se> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
Is there any way to add some code that will happen in every single Event
that i raised in a form?

I have a Total field in the bottom of a pretty complex page and I think it's kind of "Dirty" to update that Filed from every single Event that might
affect it

Is there are was to keep that Filed Total (a value) updated at all time
without having to think about it in every single event on the page?

Nomatter what happens and what fileds are updated on the page.. in a grid or in another filed, I want that Total filed to be Updated...

/Lars

Nov 20 '05 #3

P: n/a
Lars,
In addition to CJ's comments.

Have you separated your UI from your Domain/Data objects? This should be
easy! In your domain objects as properties change, the Total property would
change. If you don't have Domain (business) objects per se and are binding
directly to Data objects (such as a DataSet/DataTable) you can use the
events on the DataTable itself to update to total fields. Such as
DataTable.ColumnChanged, DataTable.RowChanged and DataTable.RowDeleted.

An alternative:
Remember that an Event can be handled by more then one handler, and that a
single handler can handle events for more then one object.

The "problem" as CJ suggested, is that the signature of the event handler
needs to match the signature of the event. You may need two extra
handlers...

You could have an extra Changed event handler that would update the total
field, for each of the UI controls, they would have their own Changed event
handler, plus this extra Changed handler would handle the changed event.

Private Sub Text1_Changed(...) Handles Text1.Changed

Private Sub Text2_Changed(...) Handles Text2.Changed

Private Sub Text3_Changed(...) Handles Text3.Changed

Private Sub AnyText_Changed(...) Handles Text1.Changed, Text2.Change,
Text3.Changed
' calculate total amount
End Sub

You can use VS.NET to set the first three Changed event handlers, however
you will need to type in the third event handler.

Hope this helps
Jay

"Lars Netzel" <[no_spam_please]la*********@qlogic.se> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
Is there any way to add some code that will happen in every single Event
that i raised in a form?

I have a Total field in the bottom of a pretty complex page and I think it's kind of "Dirty" to update that Filed from every single Event that might
affect it

Is there are was to keep that Filed Total (a value) updated at all time
without having to think about it in every single event on the page?

Nomatter what happens and what fileds are updated on the page.. in a grid or in another filed, I want that Total filed to be Updated...

/Lars

Nov 20 '05 #4

P: n/a
Lars,
I should add, rather then using the Handles syntax to add the event handlers
on the Changed event handler you could use a For Each loop over the Controls
collection and use AddHandler to add the extra event handler.

Private Sub Form1_Load(...) Handles MyBase.Load
For Each ctl As Control In Controls
If TypeOf ctl Is TextBox Then
AddHandler DirectCast(ctl, TextBox).Changed, AddressOf
AnyText_Changed
ElseIf TypeOf ...
...
End IF
Next
End Sub

Note: if you have panels & other controls that may be nested, you may need
to make the above recursive on ctl.Controls!

Hope this helps
Jay

"Lars Netzel" <[no_spam_please]la*********@qlogic.se> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
Is there any way to add some code that will happen in every single Event
that i raised in a form?

I have a Total field in the bottom of a pretty complex page and I think it's kind of "Dirty" to update that Filed from every single Event that might
affect it

Is there are was to keep that Filed Total (a value) updated at all time
without having to think about it in every single event on the page?

Nomatter what happens and what fileds are updated on the page.. in a grid or in another filed, I want that Total filed to be Updated...

/Lars

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.