|
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 is before saving the data to the database. 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. You should modify the data after extracting it from the user
interface and before it is inserted (updated) into the database.
The best way to modify a field value is to override the GetUIData() method at
the record level, typically for an Add Record or Edit Record page. In the overridden
GetUIData() method:
- Call base.GetUIData() to get the data from the user interface control.
- Get the record by calling this.GetRecord().
- Set the new value using myRec.MYFIELD = NEWVALUE.
The following code example uses the Customers table in the Northwind database.
Add this code customization to the RecordControl class located in:
.NET Framework 1.1:
|
...\<App Folder>\Customers\AddCustomersPage.Controls.cs or .vb
|
.NET Framework 2.0:
|
...\<Application Folder>\App_Code\Customers\AddCustomersPage.Controls.cs or .vb
|
C#:
public override void GetUIData()
{
  base.GetUIData();
  CustomersRecord record = this.GetRecord();
  record.LastName = "new value”;
}
|
Visual Basic .NET:
Public Overrides Sub GetUIData()
    MyBase.GetUIData
    Dim rec As CustomersRecord = Me.GetRecord
    rec.LastName = "new value"
End SubSee Also
|
|