One way to intercept record deletion in your generated application is to override the
DeleteButton_Click() button handler method.
- Anh Trinh, Software Engineer, Iron Speed, Inc.
November 1, 2006
Iron Speed Designer V4.0
Override the Delete Button Handler
In some cases it is useful to intercept record deletions in your generated application. For
example, suppose you do not want certain selected records to be deleted when your user clicks
the "Delete" button? One way to accomplish this is to override the DeleteButton_Click() button
handler method. In the example below, we check an order’s postal code when the user clicks the
"Delete" button. If the postal code is "11111", then the deletion is cancelled and an error message
is displayed; otherwise, the selected record is deleted.
Override the DeleteButton_Click() handler method in the OrdersTableControl class, located in:
.NET Framework 1.1:
...\<App Folder>\Orders\ShowOrdersTablePage.Controls.cs. or .vb
.NET Framework 2.0:
...\<App Folder>\App_Code\Orders\ShowOrdersTablePage.Controls.cs or .vb
Public Overrides Sub OrdersDeleteButton_Click(ByVal sender As Object, ByVal args As EventArgs)
Try
DbUtils.StartTransaction
Dim reclist() As OrdersTableControlRow = Me.GetSelectedRecordControls
For Each rec As OrdersTableControlRow In reclist
If rec.ShipPostalCode.Text.Equals("11111") Then
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "Cannot delete record", "Cannot
delete record")
Return
End If
Next
Me.DeleteSelectedRecords(false)
Me.Page.CommitTransaction(sender)
Catch ex As Exception
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE",
ex.Message)
Me.Page.RollBackTransaction(sender)
Finally
DbUtils.EndTransaction
End Try
End Sub
About the Author
Anh Trinh
Software Engineer, Iron Speed, Inc.
Anh is a software engineer at Iron Speed, Inc. He enjoys developing applications
with Iron Speed Designer and Microsoft .NET technology.