Geeks With Blogs

Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with

Narendra Tiwari

I remember in 2006 we were working on a portal for our client Venetian, Las Vegas and the portal is full of AJAX features. One of my friend facing a challange to retain browser history with all AJAX operation. In terms of user experience it is an important aspect which could not be avoided in that scenario. Well that time we have made some workarounds to achieve the same but that may not be the perfect solution.

Ok.. Now with Microsoft AJAX there are a lot of such features can be achieved with optimum efficiency. Microsoft AJAX has grown its features over the past few years. Microsoft.Web.Preview.dll is an addon in conjunction with ASP.Net AJAX. It contains a control named "History" for that purpose.

Source code:-

Below is a small sample to demonstrate the control.
1/ Get dll from the above source code bin, and add reference to your web application.
2/ Rightclick on toolbox panel and Choose Item, browse assembly. now you will be able to see History control.
3/ Add below section group in web.config under <configSections>

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

4/ Now create a simple webpage a textbox (txt1), button (btn1)  in an updatePanel with History control (History1). We will fill in text box and post the fom by clicking button a few times then verify if the browse history is retained. Remember button and textbox must be inside UpdatePanel and History control outside the UpdatePanel.
<%@Page Language="C#" AutoEventWireup="true" CodeFile="History.aspx.cs" Inherits="History" %>
@ Register Assembly="Microsoft.Web.Preview" Namespace="Microsoft.Web.Preview.UI.Controls" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
html xmlns="" >
head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<cc1:History ID="History1" runat="server" OnNavigate="History1_Navigate">
<asp:UpdatePanel ID="up1" runat="server">
<asp:TextBox ID="txt1" runat="server"></asp:TextBox><br />
<asp:Button ID="btn1" runat="server" Text="Test" OnClick="btn1_Click" />
<asp:AsyncPostBackTrigger ControlID="History1" />

5/ Below code to add the textbox value in history everytime we post back using btn1 click. 
protected void btn1_Click(object sender, EventArgs e)

6/ and finally Navigate event of History control
protected void History1_Navigate(object sender, Microsoft.Web.Preview.UI.Controls.HistoryEventArgs args)
string strState = string.Empty;
if (args.State.ContainsKey("txtState"))
strState = (
txt1.Text = strState;

Now all set to go :)



Posted on Friday, April 23, 2010 11:47 AM .Net | Back to top

Comments on this post: Browser History ASP.Net AJAX: Microsoft.Web.Preview

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Narendra Tiwari | Powered by: