|
You can easily modify data before saving it in the database, such as when encrypting passwords
and adding audit trail data to a record. The best way to modify data before saving is to catch
the PostGetUIData event in the customizable class of your web page.
When the user clicks on a button to save the data on the page, the data must first be extracted
from the user interface controls and copied into a database record so it can be saved into the
database. This event is sent after the data is extracted from the user interface controls into
a database record. All the validation of the data is complete before this event is sent.
This event, either at the page, table control or record control class level, is the ideal place to
add customizations to modify the record being saved. For example, this event can be handled to set
the values of additional fields on the record before it is saved.
The best way to add validation for a field is to either enable the custom validator or override the
ValidateData method at the record class level instead of handling this event.
Iron Speed best practices recommend handling the PostGetUIData event at the record control class level
instead of handling the event at the page or the table control class. This provides finer control of
since the data for other fields is available for the specific record by calling the GetRecord method.
In the PostGetUIData event handler:
- Call Me.GetRecord(True) to get the record being saved. Pass True so you get an editable record.
- Set the new value using myRec.MYFIELD = NEWVALUE
In the following code samples, replace {Table Name} with the name of your database table, such as
Customer. Replace {Field} with the name of the field you want to change.
Visual Basic .NET
Private Sub RecordControl_PostGetUIData(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.PostGetUIData
' Use the Me.GetRecord to retrieve the record that was updated.
' Pass True to GetRecord() to get updatable record.
' Pass False to GetRecord() to get read only record.
Dim myRecord As {Table Name}Record
myRecord = Me.GetRecord(True)
myRecord.{Field} = "newValue"
End Sub
|
C#
private void RecordControl_PostGetUIData(object sender, EventArgs e)
{
// Use the this.GetRecord to retrieve the record that was updated.
// Pass true to GetRecord() to get updatable record.
// Pass false to GetRecord() to get read only record.
{Table Name}Record myRecord;
myRecord = this.GetRecord(true);
myRecord.{Field} = "newValue";
}
|
|