If you model your Web application to follow a particular navigation path, you probably wrapped up your navigation paths through an action or a verb. This action or verb is usually realized as a function name. That function provides the means necessary to navigate through the different stages of a site.
However, sometimes you may want to encapsulate the navigation through a single point of entry, such as for wizard-type applications. As the user progresses through the particular stages of an application, different actions occur for collecting data. Any single action refers back to the same entry page where the business logic determines to what stage the user should be directed.
Putting all this business logic in one source is feasible, but it can get difficult to manage. In order to provide the single point of entry while dividing up responsibility, use the Server.Execute method in ASP.
Managing apps using the Server.Execute method
The Server.Execute method takes an ASP page as a parameter and passes the functionality on to it. The defined page runs as a separate process yet its output goes to the existing Response and can access all the QueryString and Form data of the Request object. This makes it handy to manage resources since you don't have to instantiate all the resources that you might need if you were to put all your logic in one page.
Let's say you were creating an application that gathered user information for a particular use case. Let's say the use case is "Input Shipping Information". In order to guide the user through a particular sequence for this use case, you want to collect the shipping address, you want to collect the carrier information, and you want to display the shipping detailed information and have the user okay this information. You have one page, InputShippingInformation.asp. Through this one page you realize the following actions: GetShippingAddress, GetCarrier, GetCarrierDetails, ReviewShipping, and SubmitShipping. The result of each action is InputShippingInformation.asp. The coordinating function for each action uses the Server.Execute method to direct the process to the coordinating page. View the sample in Listing A.
From this code snippet, you can see that the navigation is executed through an "actionverb" Request item. In each function (or Sub) that realizes the action, the Server.Execute moves execution to the specified ASP page. When the specified page receives execution, only the Application, Session, and Request objects transfer any application data. Any local objects or variables that you defined and used in the InputShippingInformation.asp page are no longer available.
Unlike the Response.Redirect method, the browser is not instructed to navigate to another page. Therefore, the browser still thinks that it is navigated to InputShippingInformation.asp. This can also add some level of security to your application. View the GetShippingAddress.asp page in Listing B.
Notice that I did not specify an action attribute for the FORM tag. The browser will submit the information to the current page when the submit event occurs. This helps make this particular page usable not only in the InputShippingInformation.asp page, but also anywhere you need to call a Server.Execute method to gather shipping information. Also, I ended the Response with the End method, because after the Executed page is complete execution will return back to the calling page.
The Member object is an object that contains information about the currently logged in user. (For simplicity's sake, I'm not going to go into the details on how to create this functionality.) Using the Member information, I can pre-populate the data fields for the shipping address. Once the user fills in the appropriate data fields and hits the Submit button, the "actionverb" form data sends the page to the next action.
If you would like to see the full source for this application, you can download it here.
Phillip Perkins is a contractor with Ajilon Consulting. His experience ranges from machine control and client server to corporate intranet applications.