IMAT1604: Visual Web Development
Web Page Code Behind
When the user clicks on the delete button an action occurs.
The code for this action is stored in a C# code file linked to
the web page. This file is referred to as the code-behind file.
It can be created by double clicking on the Delete Button in
design view, and changing the method name. The method name needs
to match the name in the onclick parameter in the web page code.
The method contains code that will be called when the user
clicks the button when the program is running.
As the user enters the record id into a text
box, the users value must be retrieved as text, and then the
code tries to convert it to a number (int id).
If the user makes a mistake and enters characters
that are not appropriate for a number (e.g. letters), the attempted
conversion will fail, (and an Exception will be caught)
with an appropriate error message displayed.
The code shown above is the final version, initially there will
be no WineList class, and therefore it the WinesId is successfully
converted the message will just say something like "You are trying
to delete a record, but the code does not exist yet!"