|
In some cases it is useful to intercept the DeleteRecord event in your generated application.
For example, suppose you do not want the selected record to be deleted when a user clicks the “Delete”
button if the unit price is greater than $10. This can be easily done by overriding the OnApplicationEvent
method in the corresponding TableControl class and handling the DeleteRecord event within it. The TableControl
class is in the page’s code-behind file, such as ShowOrder_DetailsTablePage.aspx.cs.
For .NET Framework 1.1, ShowOrder_DetailsTablePage.aspx.cs is located in
|
...\<Application Folder>\Order_Details\ShowOrder_DetailsTablePage.aspx.cs
|
Handle the DeleteRecord event within the OnApplicationEvent() function in the TableControl class.
Since OnApplicationEvent gets called when an Edit, New, or Delete button is clicked, we need to call
the base OnApplicationEvent for all other events except the DeleteRecord event, so that processing for
all other events proceeds normally.
C#:
public override void OnApplicationEvent(ApplicationEventArgs args)
{
if(args.EventType == ApplicationEventArgs.EventTypes.DeleteRecord)
{
Order_DetailsRecord selectedRecord = this.GetSelectedRecord(true);
decimal myUnitPrice = selectedRecord.GetUnitPriceFieldValue();
if (myUnitPrice >10)
{
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this,"Cannot delete record","Cannot delete record");
return;
}
}
base.OnApplicationEvent(args);
}
|
Visual Basic .NET:
Public Overrides Sub OnApplicationEvent(ByVal args As BaseClasses.ApplicationEventArgs)
If (args.EventType =ApplicationEventArgs.EventTypes.DeleteRecord) Then
Dim selectedRecord As Order_DetailsRecord = Me.GetSelectedRecord(True)
Dim myUnitPrice As Decimal = selectedRecord.GetUnitPriceFieldValue
If (myUnitPrice > 10) Then
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "Cannot delete the record", "Cannot delete the record")
Else
'Do not stop the deletion of record and call the base OnApplicationEvent which will delete the record.
MyBase.OnApplicationEvent(args)
End If
Else
MyBase.OnApplicationEvent(args)
End If
End Sub
|
For .NET Framework 2.0, ShowOrder_DetailsTablePage.Controls.cs is located in
...\<Application Folder>\App_Code\Order_Details\ShowOrder_DetailsTablePage.Controls.cs
|
C#:
public override void OnApplicationEvent(BaseClasses. ApplicationEventArgs args)
{
if(args.EventType == BaseClasses. ApplicationEventArgs.EventTypes.DeleteRecord)
{
Order_DetailsRecord selectedRecord = this.GetSelectedRecord(true);
decimal myUnitPrice = selectedRecord.GetUnitPriceFieldValue();
if (myUnitPrice >10)
{
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this,"Cannot delete record","Cannot delete record");
return;
}
}
base.OnApplicationEvent(args);
}
|
Visual Basic .NET
Public Overrides Sub OnApplicationEvent(ByVal args As BaseClasses.ApplicationEventArgs)
If (Not args.EventType = ApplicationEventArgs.EventTypes.DeleteRecord) Then
MyBase.OnApplicationEvent(args)
End If
If (args.EventType =ApplicationEventArgs.EventTypes.DeleteRecord) Then
Dim selectedRecord As Order_DetailsRecord =Me.GetSelectedRecord(True)
Dim myUnitPrice As Decimal =selectedRecord.GetUnitPriceFieldValue
If (myUnitPrice > 10) Then
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "Cannot delete the record", "Cannot delete the record")
Else
'Do not stop the deletion of record and call the base OnApplicationEvent which will delete the record.
MyBase.OnApplicationEvent(args)
End If
End If
End Sub
|
|