I have an unbound Formview that is used for adding a new Work Order against an equipment item. In the ItemInserting event I have code that generates the pk (WorkOrderID) for the table that the record is being inserted to. I want to put a Try_Catch there which would allow me to redirect the user if for some reason the sql server is down and a new WorkOrderID did not get generated. If succesful then I want to provide a message box that tells the user the new WorkOrderID and allows them to either go to another web page to further document the Work Order or add another Work Order.
Where would be the best place to put the Try Catch function to make sure a new WorkOrderID was generated? I put it where I thought it might go but not too sure.
Which event would I use to redirect the user once a new record was inserted and a WorkOrderID generated? ItemInserted perhaps?
To redirect the user once the record is inserted I would need the WorkOrderID generated, how do I store that in a global variable after it is generated so I can then grab it later?
Thanks for any help
I have inserted what I have so far.
Protected Sub fvAddWorkOrder_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles fvAddWorkOrder.ItemInserting
Dim newWorkOrderID As New NewWorkOrderID 'Class created to gerenrate next incramental WorkOrderID
Dim txtDate As TextBox = DirectCast(fvAddWorkOrder.FindControl("txtDateOpened"), TextBox)
Dim dateOpened As Date = txtDate.Text ' date needed to pass into the class to detrmine next woID
Dim nextWorkOrderID As String = newWorkOrderID.NewWorkOrderID(dateOpened).ToString()
e.Values("WorkOrderID") = nextWorkOrderID
Catch ex As Exception
MsgBox("There was a problem generating the Work Order. Contact System Administrator at 552-7604")