Override the DeleteRecord Event
In some cases it is useful to intercept the DeleteRecord event in your generated application...This can be easily done by overriding the OnApplicationEvent method in the corresponding TableControl class and handling the DeleteRecord event within it.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

March 29, 2006
Iron Speed Designer V3.2

Procedure
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

About the Author
Pooja Daga
Technical Support Engineer, Iron Speed, Inc.

Pooja has experience developing Web applications using .NET technology. She started her career with PCS, a leading software services company headquartered in India and has been with Iron Speed since 2005.

Pooja holds an M.S. degree in Computer Application and a B.S. degree in Electrical engineering from Maharaja Sayajirao University in India.



  Privacy Statement