Sunday, August 3, 2008

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"/>


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">


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


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


int startPage = 0;

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


startPage = (



GridView1.PageIndex = startPage;



void GridView1_PageIndexChanged(object sender, EventArgs e)



"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 previous post

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

Sorry for the my code formatting, I tried to explain the steps, I hope this will help you.


Mansoor said...

Thanks Brij.......It definately helped me as i have got only 2005 in my system.

Anonymous said...

Thanks a lot brij..... ur code snippet made wonders in my work....

Keep this sharing going on....

Anonymous said...

Thanks a lot brji...

i am using vs2005 with history control.its working fine,but in when i click next button it will goes to next page but in address bar it will display

extra content added in the address bar how to revove that can u plz....

Post a Comment