fredag 5 oktober 2007

ASP.NET Ajax History control example

This is a short example how to set up the History control from ASP.NET Futures and ASP.NET AJAX.

<cc1:History ID="History1" runat="server"></cc1:History>

<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">

<ContentTemplate>

<asp:MultiView ID="multiView" runat="server">

<asp:View id="viewStep1" runat="server">

...

</asp:View>

<asp:View ID="viewStep1" runat="server">

...

</asp:View>

</asp:MultiView>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTrigger ControlID="History1" EventName="Navigate" />

</Triggers>

</asp:UpdatePanel>

Event that is fired when you press the back button.

public void History1_Navigate(object sender, Microsoft.Web.Preview.UI.Controls.HistoryEventArgs args)

{

string viewId = "";

View historyView = viewStep1;

if (args.State.ContainsKey("BookingSteps"))

{

viewId = (string)args.State["BookingSteps"];

}

foreach (View v in multiView.Views)

{

if (v.ID == viewId)

historyView = v;

}

setActiveView(historyView);

}

Set history point each time you change the view.

private void setActiveView(View view)

{

multiView.SetActiveView(view);

History1.AddHistoryPoint("BookingSteps", view.ID);

}

Inga kommentarer: