6.3. Enabling Partial Updates

You can easily get rid of this warning dialog by using AJAX techniques to update the page. That way, the page isn't actually reloading, so the browser can refresh the page without warning the user. The simplest way to do that of course is to wrap the search box and ListView in an UpdatePanel control, as in Listing 6-3 (AlbumSearchUpdatePanel.aspx). The code-behind for this page (AlbumSearchUpdatePanel.aspx.cs) is the same as in Listing 6-2 since no logic has changed, except the class name is AlbumSearchUpdatePanel.

Example 6-3. AlbumSearchUpdatePanel.aspx
<%@ Page Language="C#" CodeFile="AlbumSearchUpdatePanel.aspx.cs"
    Inherits="AlbumSearchUpdatePanel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Phish Album Search</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox id="txtSearch" runat="server" /> <asp:Button ID="cmdSearch" runat="server" Text="Search" /> <asp:ListView ID="AlbumList" runat="server"> <LayoutTemplate> <p> Sort Order: [<asp:LinkButton ID="SortByTitle" runat="server" CommandName="Sort" CommandArgument="Title" Text="Title" /> | <asp:LinkButton ID="SortByDate" runat="server" CommandName="Sort" CommandArgument="ReleaseDate" Text="Release Date" />] ...

Get Professional ASP.NET 3.5 AJAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.