Step 7 - Registering the Order Business Object with the Form

In this step you will register the Orders business object with the Customer Orders form. This object will be used to retrieve orders for a specified customer.

  1. In the Solution Explorer, right-click the CustomerOrders.aspx file and select View Code from the shortcut menu.

  2. If you added a reference to the Order System Business Objects EF project, at the top of the source code file, add a reference to the following namespace:

    Imports Acme.OrderSystem.BusinessEF
    

    If you added a reference to the Order System Business Objects EF Code First project, add a reference to the following namespace:

    Imports Acme.OrderSystem.BusinessCF
    

    This is needed to reference the application's custom business classes.

  3. At the top of the class definition, add the following protected property that will be used to store a reference to the Orders business object.

    Public Class CustomerOrderx
    	Inherits mmBusinessWebPage
     
    	Protected Order As Order

  4. In the Web Form's Page_Load method, add the following code that instantiates the Orders business objects and registers it with the form:

    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load
    	' Instantiate the Order object and register it with the form
    	Me.Order = CType(Me.RegisterBizObj(New Order), Order)
    End Sub

  5. Next, go to the Solution Explorer and double-click CustomerOrders.aspx which opens the Web Form in design mode (if the form is already open in design mode, you can simply click the CustomerOrders.aspx tab instead).

  6. At run time, when the user enters a Customer ID in the text box and clicks the Get Orders button, we need to retrieve all orders from the specified customer by means of the Orders business object. To add this code to the form, double-click the Get Orders button. This displays the CustomerOrders.aspx.vb source code file, adding a new btnGetOrders_Click event handler method:

    Protected Sub btnGetOrders_Click(sender As Object, e As EventArgsHandles btnGetOrders.Click
     
    End Sub

  7. In a later step, you will need to call the code that retrieves customer orders from multiple places. So rather than placing the code that retrieves the orders directly in the btnGetOrders_Click method, add the following GetOrdersByCustomerID method directly below it:

    ''' <summary>
    ''' Retrieve all orders for the specified customer
    ''' </summary>
    ''' <param name="customerID">Customer ID</param>
    Private Sub GetCustomerOrders(customerID As String)
    	Me.Order.GetOrdersByCustomerID(customerID)
    End Sub

    This code calls the Order business object's GetOrdersByCustomerID method, passing the customer ID entered in the Web Form text box.

  8. Next, add a call to this method from btnGetOrders_Click:

    ''' <summary>
    ''' Get Orders for the specified customer
    ''' </summary>
    Private Sub btnGetOrders_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnGetOrders.Click
    	Me.GetCustomerOrders(Me.txtCustomerID.Text)
    End Sub

    Now that you have registered the Orders business object with the Web Form, and added the first bit of code that calls a business object service, it's time to bind the GridView to the business object.

See also:
Step 8 - Binding the GridView to the Orders Object


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/25/18
Comment or report problem with topic