12.4. Adding AJAX to the Web Parts Page

The next step will be to add AJAX capabilities to the page that was just built. This example lessens the amount of data going back and forth between the client and the server, it will also remove the flicker that happens with pages that are not using AJAX capabilities.

The first step is to add your ScriptManager server control to the page and then encapsulate much of the Web Part capabilities inside of the UpdatePanel control. This approach is illustrated in Listing 12-3.

Example 12-3. Incorporating AJAX capabilities into a page with Web Parts
<%@ Page Language="C#" %>

<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Register Src="HelloUser.ascx" TagName="HelloUser" TagPrefix="uc1" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
{ WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode; } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Label1.Text = "You selected " + Calendar1.SelectedDate.ToShortDateString(); } protected void LinkButtonBrowse_Click(object sender, EventArgs e) { WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode; } protected void LinkButtonDesign_Click(object sender, EventArgs e) { WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Web Parts with AJAX</title> </head> <body> <form id="form1" runat="server"> <div> ...

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.