Navigation

From any given State the permissible Navigations are following any child Transition or jumping to another Dialog. Navigating along a Transition will move to the State referred to in the ‘to’ attribute of the Transition and so will always remain within the same Dialog. Navigating to another Dialog will move to the State referred to in the ‘initial’ attribute. Both these are considered forward Navigations.

Taking the State Information configured in State Information as an example, The image below shows the possible Navigations between States. An example route taken by the user could be starting at Dialog, D1, and Navigating along Transition T1 and then to Dialog D2 and described by:

D1-S1 -> D1-S2 -> D2-S1
A stopping point in the above route is a State but it is represented by the ‘Dialog key - State key’ combination as this is unique, whereas the ‘State key’ alone is not.
Possible Navigations between States
Possible Navigations between States

The StateController class provides methods, called Navigate and GetNavigationLink, to perform these forward Navigations. Both these methods require an action parameter that must take one of the following values as read from the State Information configuration:

  1. Transition key – this must be the key of one of the child Transitions of the current State
  2. Dialog key – this can be the key of any Dialog
So, in the example route above these action parameters would be D1, T1 and D2.
The three different ways to move between aspx Pages in ASP.NET are:

  1. Redirect – a call is made from the Server to Response.Redirect passing a URL. This transfers control to the browser which issues a call for this URL
  2. Transfer – a call is made from the Server to Server.Transfer passing a URL. Control stays on the Server and ASP.NET ends processing of the current Page and starts processing the Page specified in the URL
  3. Hyperlink – an anchor tag is clicked in the browser and the browser makes a request for the URL specified in the href attribute (javascript calls to location.href or location.replace are synonymous with Hyperlink navigation)
The Navigation Framework StateController methods cater for each of these different types. For Redirecting and Transferring the method required is Navigate, an overload of which accepts a NavigationMode parameter which specifies whether to Redirect or Transfer (the default is Redirect); and for a Hyperlink the method is GetNavigationLink.

The StateContext class tracks the current and previous State in its State and PreviousState properties. In the example route, when the State is D2-S1 the PreviousState would be D1-S2. These properties are not strings but point to the State Information elements read from configuration and contained in the Dialogs property of the StateInfoConfig class.

Sample Web Site

The second page of the NavigationSample Web Site will display the details of a person selected from the list, so begin by adding a Web Form called Details.aspx to the Web Project. In order to navigate from the Listing.aspx to Details.aspx the StateInfo.config must be amended with the addition of a new Details State and Transition below the Listing State pointing at this State, as shown below.

<dialog key="Person" initial="Listing" path="~/Listing.aspx">
	<state key="Listing" page="~/Listing.aspx" title="Person Search">
		<transition key="Select" to="Details"/>
	</state>
	<state key="Details" page="~/Details.aspx" title="Person Details">
	</state>
</dialog>
Change the Search method to construct a URL using this Transition key and then return it in a Link property, as shown below, making sure to add a using to the Navigation namespace.

public IEnumerable Search()
{
	return from p in _People
			select new
			{
				p.Name,
				p.DateOfBirth,
				Link = StateController.GetNavigationLink("Select")
			};
}
The BoundField Name column of Listing.aspx can be changed to a TemplateField containing a HyperLink with its NavigateUrl property databound to the Link property, as shown below. For the time being the old DataBinding syntax, Eval, will be used, rather than the strongly-typed syntax introduced in VS 2012. This is because returning an anonymous type from the Search method prohibits its use, but in the Data Binding section this will be rectified.

<asp:TemplateField HeaderText="Name">
	<ItemTemplate>
		<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%#: Eval("Name") %>' />
	</ItemTemplate>
</asp:TemplateField>
Pressing F5 will display the table of three people with the first column containing a Hyperlink, clicking this link will display the blank Details.aspx Page. This is an example of navigating passing a Transition key as the action parameter to the StateController. The navigation results in the Details State because it is configured as the 'to' State of the Select Transition

The other type of navigation, where a Dialog key is passed, will be used to go from the Details.aspx Page back to Listing.aspx. To Details.aspx add a Button together with a Button Click handler (see below); in later sections this will be changed to a Hyperlink, but a button is used here to demonstrate the different types of Navigation.

<body>
    <form id="form1" runat="server">
    <div>
	<asp:Button ID="Button1" runat="server" Text="Listing" OnClick="Button1_Click" />
    </div>
    </form>
</body>
To the Click handler add the code shown below, making sure to add a using to the Navigation namespace. The uncommented line results in a Response Redirect whereas the commented line results in a Server Transfer. Pressing F5 and clicking the Hyperlink will display the Details.aspx Page; clicking the Button on this page will display the Listing.aspx Page. The navigation results in the Listing State because it is configured as the 'initial' State of the Person Dialog.

protected void Button1_Click(object sender, EventArgs e)
{
	StateController.Navigate("Person");
	//StateController.Navigate("Person", NavigationMode.Server);
}

Last edited Aug 4, 2013 at 6:17 PM by GrahamMendick, version 6