Quote:
|
I didn't think database operations were considered an event
|
They aren't, but they can raise events. In pseudo code the Inserting operation of the SqlDataSource control could like this:
Code:
Do work to prepare the Insert
' Then set up a new SqlDataSourceCommandEventArgs
Dim args As New SqlDataSourceCommandEventArgs()
Prepopulate the args with data you need in the event handler
' Raise the event to the caller:
RaiseEvent (OnInserting, args)
Perform the actual insert operation and use stuff like args.Values modified by the user
' Then raise the Inserted event
RaiseEvent (OnInserted)
In this "code", each line that doesn't start with a command could be part of the operation carried out by the control. Just before the control raises the Inserting event, it constructs a new
SqlDataSourceCommandEventArgs and passes that to *your* method defined in the page classes when it calls RaiseEvent. Your method then adds or modified values in the object using its Values or NewValues collection. Then when your method is done, the control proceeds with its operation. It carries out the actual Insert operation against the database, using the values in the Values property of the args variable. It then raises the Inserted event so you can see whether the operation succeeded or not.
Quote:
|
I thought it was more like passing a variable to a sub.
|
Yes, that's what's happening. You register an *event handler* which is a normal method, but which is designed to handle a specific event (in
VB using the Handles keyword). Then when the control raises a specific event, it makes available an EventArgs object (or a sub class of it). The run-time then calls your method and provides you with the EventArgs object with event-specific data so you can look at it, and optionally alter it.
Does this help?
Imar