Nov 12

Changing the contents of the UpdateProgress control

Posted in MS AJAX      Comments Off on Changing the contents of the UpdateProgress control

Today I”ve answered a question on the ASP.NET AJAX forums that  asked something like this: how do I get a reference to the controls defined inside an UpdatePanel or UpdateProgress controls? The first part is easy: just use the ID of the control. The second is not as easy as it might seem at first. The problem is associated with the way the control isntantiates the template on the PreRender event.

What this means is that you might have to write code similar to this if you want to get a reference to a control placed inside the UpdateProgress in order to change its properties:

<%@ Page Language=”C#” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<script runat=”server”>
    void E(Object sender, EventArgs e)

    private Boolean update = false;
    void J(Object sender, EventArgs e)
        update = true;

    protected override void  Render(HtmlTextWriter writer)
        if (update)
            Label lbl = (Label) progress.FindControl(“lbl”);
            lbl.Text = DateTime.Now.ToString();


<html xmlns=””>
<head runat=”server”>
    <title>Untitled Page</title>
    <form id=”form1″ runat=”server”>
         <asp:ScriptManager ID=”ScriptManager1″ runat=”server” />
         <asp:UpdatePanel runat=”server” ID=”panel”>
                <asp:Button runat=”server” id=”bt” text=”partial postback” OnClick=”E”/>
         <asp:Button runat=”server” text=”full postback” OnClick=”J” />
         <asp:UpdateProgress runat=”server” ID=”progress” AssociatedUpdatePanelID=”panel”>
                <asp:Label runat=”server” id=”lbl” />