Blogger :
Atlas and more
All posts :
All posts by Atlas and more
Category :
AJAX
Blogged date : 2008 Jan 05
I've recently recorded a screencast showing how to enable server-side history management (in other words, handling the back button) in an ASP.NET Ajax application. The whole video is less than 15 minutes total and I build the whole application from scratch in there (in VB).
I hope it shows just how simple history management is made by ASP.NET Ajax and that it helps understanding the state model that it's built on.
The same video in a variety of formats and in a resolution where the code is actually readable can be found here:
http://www.asp.net/downloads/3.5-extensions/
For those people who find it difficult to cut and paste code from a video by doing a screen capture and then using OCR over it, here's the source code of the mini-app that's being built in the video:
Default.aspx:
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnableHistory="True" EnableStateHash="False"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Wizard ID="Wizard1" runat="server">
<WizardSteps>
<asp:WizardStep runat="server" Title="Step 1">
<asp:TextBox ID="TextBox1" runat="server"/>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 2">
<asp:TextBox ID="TextBox2" runat="server"/>
</asp:WizardStep>
<asp:WizardStep runat="server" Title="Step 3">
<asp:TextBox ID="TextBox3" runat="server"/>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</ContentTemplate>
</asp:UpdatePanel>
Default.aspx.vb:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Wizard1_ActiveStepChanged(_
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Wizard1.ActiveStepChanged
If ScriptManager1.IsInAsyncPostBack And _
Not ScriptManager1.IsNavigating Then
ScriptManager1.AddHistoryPoint("index", _
Wizard1.ActiveStepIndex, _
"Wizard step " & Wizard1.ActiveStepIndex)
End If
End Sub
Protected Sub ScriptManager1_Navigate(_
ByVal sender As Object, ByVal e As HistoryEventArgs) _
Handles ScriptManager1.Navigate
Dim indexString As String = e.State("index")
If String.IsNullOrEmpty(indexString) Then
Wizard1.ActiveStepIndex = 0
Else
Dim index As Integer = Convert.ToInt32(indexString)
Wizard1.ActiveStepIndex = index
End If
Page.Title = "Wizard step " & indexString
End Sub
End Class
http://www.asp.net/downloads/3.5-extensions/