Home > Articles > Programming > Visual Basic

  • Print
  • + Share This
Like this article? We recommend

Multiple Actions

ASP applications are typically implemented with one ASP file per user action. This is analogous to developing a Windows application, in which each event procedure is coded in a separate file—this is much too complex, in my opinion. But by using the VB IDE, it is possible to include a Web application's entire set of logic (or as much as you want) into a single VB ActiveX DLL project.

Suppose that our sample application has three actions. One action sends a form that allows the user to enter search criteria (see Figure 1 below). Another action gets the search criteria from the form and returns the form with an HTML table that contains all publishers that have a name that matches the criteria (see Figure 2 below). Finally, the third action sends a page that lists the detailed information about the publisher who was selected in the table list (see Figure 3 below).

Figure 1

Figure 2

Figure 3

The immediate question is, "How does the Web UI component know which action the user is requesting?" My solution is to use query string values to tell the code which action is being requested. For example, the URL to send the search form might be PubWebUI.asp?action=SearchSend, the URL to process the form might be PubWebUI.asp?action=SearchProc, and the URL to send the publisher's detail information might be PubWebUI.asp?action=DetailProc. This solution for handling multiple actions affects the WebMain method because it must now inspect the query string action value in order to determine what to do. Consider this example:

Public Sub WebMain()
    On Error GoTo ErrHandler
    Select Case gAspReq.QueryString("Action")
        Case "SearchSend"
            Call SearchSend
        Case "SearchProc"
            Call SearchProc
        Case "DetailProc"
            Call DetailProc
        Case Else ' Otherwise send a default page.
            Call SearchSend
    End Select
    Exit Sub

    Call gAspResp.Write(Err.Description)

End Sub

Note that the actual processing logic for these three actions has been delegated to private subprocedures, and that an error handler has been added to catch any run-time errors that might occur in these subprocedures.

As you add new features to your Web application, you simply create new mnemonics for the various actions to perform, communicate them with the HTML author, and add them to the Select Case statement in the WebMain method.

  • + Share This
  • 🔖 Save To Your Account