Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Using Windows Workflow to Control ASP.NET Navigation : Page 4

Windows Workflow is not only ideal for defining page-flow logic visually, but also for letting different systems communicate.

Adding Pageflow Logic
At this point, the workflow can request information (name and user choices) and receive the information back. Now it's time to add the final bit of logic that controls page flow depending on whether the user chose to "show page 2."

Go back to the designer canvas of the workflow and add an IfElseActivity underneath the handleNameAndPage activity as shown in Figure 8.

Figure 8. Add IfElseActivity: Here's how the workflow should look after you drag a new IfElseActivity to the design surface.
Figure 9. Modified IfElseActivity: Here's how the workflow should look after deleting the else branch and renaming the activity, along with the new IfElseActivity Properties dialog.
In this case, you're not going to use the else branch because you just need to check whether "viewPage2" is in the data returned from the initial page. Delete the else branch by selecting the right-hand side of the branch and pressing Delete. You should now end up with just one branch. Select that, and then open its properties dialog. In the dialog, rename the activity
Figure 10. Adding a Declarative Rule: When you select the Declarative Rule Condition type, two child rows appear under the Condition item.
to ifPage2Required—the activity and its properties should look like Figure 9.

You also set the condition for IfElseActivities in the activity Property dialog. Select the right-hand side of the Condition row in the properties screen. You'll see a drop-down list. Clicking the drop-down gives you the choice to add either a code condition or a declarative rule condition. Select the latter. Two child rows will appear as shown in Figure 10.

Type something for the ConditionName field such as page2Specified and then click the ellipsis in the Condition Expression field. This brings up a dialog box with the name of the expression. Click the Edit button and add the following code:

(bool)this.nameAndPageChoicesArgs.PropertyBag[ "viewPage2"] == true

Figure 11. Calling Page Two: An additional CallExternalMethod activity handles the call to page two of the application.
Step one of the workflow asks for data. Step 2 stores the response. This condition checks whether an item in the property bag is true. Remember, this field in the property bag gets set when a user clicks the "Next" button on the first page. So, if the value is true, the user wants to view page 2—so add another CallExternalMethod activity into the ifElseActivity branch (see Figure 11).

Figure 12. Final Workflow: Here's how the workflow should look after adding the final activities.
As in the first request, the code calls the RequestInformation method on the IGenericInformationService interface, and passes in as a parameter the string "page2."

At this point, the GenericInformationService.RequestInformation method gets called in the concrete class. This then fires the event InformationRequested, which the ASP.NET application receives. Control then shifts to ASP.NET to decide which page to redirect to. When it's finished, control returns to the workflow.

The very last bit involves waiting for a response from "page 2" and then calling "page 3." So, add a HandleExternalEvent activity in the ifElse branch and then add another CallExternalMethodActivity (outside of the branch) and set the informationName property to "page 3" as shown in Figure 12

This document has described a simple way for WF and ASP.NET to talk to each other by building an example that shows how to integrate WF into your ASP.NET applications to control simple page-flow logic. There are doubtless many other ways to achieve the same result, but the other ways I've seen appear (to me anyway!) to be slightly more complex.

Steve Dunn started programming in the 1980s, writing eight-bit computer games. Since then he has worked mainly in interactive media and banking. His primary areas of interest are framework design and extreme programming.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date