Using ASP.NET AJAX Features

How to use ASP.NET AJAX features

You can include ScriptManager in a User Control function or ASP.NET Control and thus use the ASP.NET AJAX features.

<asp:ScriptManager ID="ScriptManager1" runat="server" AjaxFrameworkMode="Enabled" />
Use the simple sample below to see how it can be implemented:

  1. From the "Functions" perspective, create a User Control function, for example, "Test.AjaxUse".
  2. Copy the code from the samples below to the function.
  3. Edit a page.
  4. Insert the "Test.AjaxUse" User Control function on the page ("Insert" / "Functions").
  5. If needed, switch to "Source" mode and wrap the inserted function with <asp:form/>.
  6. Save and publish the page.

AjaxUse.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AjaxUse.ascx.cs" Inherits="C1Function" %>

<asp:ScriptManager ID="ScriptManager1"  runat="server"  AjaxFrameworkMode="Enabled" />
<asp:UpdatePanel ID="UpdatePanel1"  runat="server"  ChildrenAsTriggers="true"  UpdateMode="Always">
    <ContentTemplate>
        <%= DateTime.Now %>.<%= DateTime.Now.Millisecond %><asp:Button ID="Button1"  runat="server"
            Text="AJAX" />
    </ContentTemplate>
</asp:UpdatePanel>
Download AjaxUse.ascx

AjaxUse.ascx.cs:

using System;
using Composite.Functions;

public partial class C1Function : Composite.AspNet.UserControlFunction
{
    public override string FunctionDescription
    {
        get 
        { 
            return "A demo function that uses ASP.NET AJAX."; 
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
Download AjaxUse.ascx.cs

In the above sample, clicking the "AJAX" button refreshes the part contained within UpdatePanel - in this case, the date and time.

Setting ChildrenAsTriggers to 'True' (default) and UpdateMode to 'Always' (default) causes postbacks from immediate child controls of the UpdatePanel control to update the panel's content. In this sample, these attributes are set explicitly.