Welcome!

.NET Authors: Liz McMillan, Yakov Werde, Matthew Pollicove , Kevin Benedict

Related Topics: .NET, AJAX & REA

.NET: Article

A Primer on Microsoft Atlas

AJAX-ifying your applications

Now that we've seen what the ScriptManager is capable of, let's see how it handles the errors or exceptions that can occur during an asynchronous post back. By default, the ScriptManager traps exceptions and displays them as a message box. This may be not be the best way to convey that information to the user so the developer might want to replace it with one that's more user friendly. ScriptManager provides a way for a developer to do some error handling by defining an OnPageError event handler and assigning a custom error message .The error message can be displayed as an overlay over the page by defining an ErrorTemplate. At a minimum, this error template should contain a span or div element with the pre-set id errorMessageLabel and a button used to dismiss the error message. Before we round up our discussion about the ScriptManager, there's one more control, the ScriptManagerProxy that's a close relative. It's used in case the page already has an instance of the ScriptManager control and one of the controls needs to add a script or a service reference. It can also be used in a scenario where the Master page has a ScriptManager control already defined and the content page needs to add scripts or services.

UpdatePanel
After the script manager, the UpdatePanel is the next most important Atlas server control. It lets the developer divide the page into different sections and lets each section be updated independently without refreshing the entire page. This functionality translates straightaway into better user interactions; partial refreshes are less disruptive than regular full page refreshes. In reality, the UpdatePanel generates a post back similar to the regular post back and in fact most of the page events are triggered.

The Page.IsPostback even returns a true value for an update panel post back. Where the UpdatePanel post back differs from a normal post back in the page lifecycle is in the render event. In the case of an UpdatePanel post back, only those regions defined by the UpdatePanel are rendered and sent back to the client.

On the client side, the child controls of the UpdatePanel are replaced with the new content. This is known as partial rendering. For an UpdatePanel to work in partial rendering mode, it requires a ScriptManager with the EnablePartialRendering attribute set to true.

<atlas:UpdatePanel runat="server" ID="UpdatePanel2" Mode="Always">
   <ContentTemplate>
      <asp:label runat="server" Text="Keep changing me!" ID="Label1" />
   </ContentTemplate>
</atlas:UpdatePanel>

Now that we're familiar with what partial rendering is, let's look at the UpdatePanel control in detail .The code snippet above shows the markup for an UpdatePanel. The UpdatePanel exposes a ContentTemplate. Any content that needs to be replaced by partial rendering needs to be inside the ContentTemplate. The UpdatePanel also has an attribute Mode that defines when the UpdatePanel content would be refreshed. Setting it to Always refreshes the content during each and every post back. If this isn't the case and the UpdatePanel is to be refreshed in response to certain events, it's possible by setting the value of the Mode attribute to conditional. After that, set the trigger that would cause the update. The UpdatePanel can accept a collection of triggers that would cause an update. These triggers are classified into two types:

  • ControlEventTrigger - This is a trigger that causes an UpdatePanel refresh in response to a control event. To set a ControlEventTrigger, specify the ID of the control and the name of the event that would trigger the update. In the control event trigger defined below, the UpdatePanel is set to refresh when the button is clicked.

    <Triggers>
         <atlas:ControlEventTrigger ControlID="btnTrigger" EventName="Click" />
    </Triggers>

  • ControlValueTrigger - This trigger is fired when the property value of a control is changed. In the sample code below, the control value trigger will fire when the textbox text changes.

    <Triggers>
         <atlas:ControlValueTrigger ControlID="txtMessage" PropertyName="Text" />
    </Triggers>

    TimerControl
    The timer control is used to set a timer event and refresh the UpdatePanel or the page at set intervals. The interval for the timer control is set in milliseconds. It's also possible to define a handler for the OnTick event. The timer control is a popular choice as a trigger for an UpdatePanel. The code snippet below shows a timer control.

    <atlas:TimerControl runat="server"
    Interval="15000" ID="tickerTimer"
    OnTick="tickerTimer_Tick" />

    UpdateProgress
    UpdateProgress is a nifty little control that lets a developer display a templated message when an asynchronous post back is in progress. It's used to cue the users that something is happening in the background. The UpdateProgress control defines a ProgressTemplate. Any content to be displayed when an update is in progress has to be enclosed between the ProgressTemplate tags. In the code snippet below, when an asynchronous update is in progress, a div tag with an image and text is displayed and it is hidden as soon as the update is complete.

    <atlas:UpdateProgress ID="upe" runat="server">
        <ProgressTemplate>
           <div class="update">
          <img src="../Images/icons/indicator.gif" alt=""/>
        Updating....</div>
        </ProgressTemplate>
        </atlas:UpdateProgress>

    Extenders and the Control Toolkit
    Extenders are a set of controls used to enhance or extend the behavior of existing ASP.NET controls. They offer a variety of functionality and let developers easily spruce up their Web sites with little or no effort. The Atlas framework provides a set of extenders out-of-the-box and support for creating new ones. Although a lot of the current crop of extenders that provide client-side behavior have little to do with AJAX, having these behaviors packaged as a control makes it easy for a developer to use them and reuse the logic elsewhere.

    The control toolkit is a collection of extenders. It provides the developer with a way to develop reusable Atlas controls and includes the full source code, documentation, and samples to help. According to Scott Guthrie, general manager of Microsoft's Developer Division, Microsoft plans to develop the toolkit as a collaborative Open Source project so both Microsoft and non-Microsoft developers can work on it. This model would definitely expand the control toolkit by many more extenders. Let's take a look at some of the extenders available in the April CTP version of Atlas.


  • More Stories By Jeevan Murkoth

    Jeevan Murkoth is a Microsoft Certified Solutions Developer (MCSD) in .NET (Early Achiever) and a Microsoft Certified Application Developer (MCAD) in .NET. He currently consults for Tennessee Valley Authority and lives in Chattanooga, TN. He has an MS in Management Information Systems from Texas Tech University.

    Comments (1) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Most Recent Comments
    AJAXWorld News Desk 08/01/06 01:17:17 PM EDT

    Ever since the advent of the Internet, Web applications have lagged behind desktop applications in terms of interactivity and responsiveness. One of the biggest drawbacks in the conventional Web model has been the cycle of inactivity between the user request and the server response. Reducing this period of inactivity has been the point of focus for any developer who wants to improve the responsiveness of Web applications and raise the user experience to levels offered by desktop applications.