Using ASP.NET 3.5 History Control with ASP.NET 2.0

Using Back Button in ASP.NET 2.0 and AJAX

This post will show you how to use ASP.NET 3.5 Ajax COntrolToolKit History control with ASP.NET 2.0,

As you might be aware of that microsoft has included AJAX with Framework 3.0, and from version 3.5 microsoft has also included History control in his AJAX Control toolkit,

Using history control we can use browser back button to navigate backwards in the pages containing AJAX Controls, which was normally not possible till Framework 2.0.

But if you are still using ASP.NET 2.0, then don't get disappointed you can use the same control in ASP.NET 2.0, remember to use this you don't need to install Framework 3.0, or 3.5.

You just need to do the steps given below:

1. Download the DLL, Microsoft.Web.Preview.dll, version 1.1.61025.0 or alrernatively download the source code from here and copy the DLL from bin folder.

2. From the Toolbox of you project, right click and Select Choose Items...

3. Locate the Microsoft.Web.Preview.dll and select OK.

4. You can find see the following tiems in the screenshot below, are added in your toolbox.

 
 
 

 

5. Now add the code below in your web.config

<sectionGroup name="microsoft.web.preview" type ="Microsoft.Web.Preview.Configuration.PreviewSectionGroup, Microsoft.Web.Preview">

<section name="search" type ="Microsoft.Web.Preview.Configuration.SearchSection, Microsoft.Web.Preview" requirePermission ="false" allowDefinition="MachineToApplication"/>

<section name="searchSiteMap" type ="Microsoft.Web.Preview.Configuration.SearchSiteMapSection, Microsoft.Web.Preview"

requirePermission ="false" allowDefinition="MachineToApplication"/>

<section name="diagnostics" type="Microsoft.Web.Preview.Configuration.DiagnosticsSection, Microsoft.Web.Preview"

requirePermission ="false" allowDefinition="MachineToApplication"/>

</sectionGroup>

6. Once you are done with this, open the webpage where you want to use the history control, and add the code below.

<asp:History ID="History1" runat="server" OnNavigate="History1_Navigate">

</asp:History>

 

7. Open the codebehind and add the following piece of code

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

{

int startPage = 0;

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

{

startPage = (int)args.State["StartPage"];

}

GridView1.PageIndex = startPage;

}

protected void GridView1_PageIndexChanged(object sender, EventArgs e)

{

History1.AddHistoryPoint("StartPage, ((GridView)sender).PageIndex);

}

And thats it!!! You are ready to go...

 

This code uses GridView Paging, to demonstrate the HistoryControl

 

You can download the running sample from the here,

C# Code, VB.NET Code

 

You can also refer my post

Using ASP.NET 3.5 Extensions History Control for complete Samples and Videos.

 

1 Comment

Comments have been disabled for this content.