Permalink
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (35 sloc) 3.53 KB
uid title author description ms.author ms.date ms.assetid msc.legacyurl msc.type
web-forms/overview/ajax-control-toolkit/animation/animation-depending-on-a-condition-cs
Animation Depending On a Condition (C#) | Microsoft Docs
wenz
The Animation control in the ASP.NET AJAX Control Toolkit is not just a control but a whole framework to add animations to a control. Whether an animation is...
riande
06/02/2008
b7a28c0d-efb9-443a-80a4-1a5ee54671cd
/web-forms/overview/ajax-control-toolkit/animation/animation-depending-on-a-condition-cs
authoredcontent

Animation Depending On a Condition (C#)

by Christian Wenz

Download Code or Download PDF

The Animation control in the ASP.NET AJAX Control Toolkit is not just a control but a whole framework to add animations to a control. Whether an animation is run or not can also depend on a condition in form of some JavaScript code.

Overview

The Animation control in the ASP.NET AJAX Control Toolkit is not just a control but a whole framework to add animations to a control. Whether an animation is run or not can also depend on a condition in form of some JavaScript code.

Steps

First of all, include the ScriptManager in the page; then, the ASP.NET AJAX library is loaded, making it possible to use the Control Toolkit:

[!code-aspxMain]

The animation will be applied to a panel of text which looks like this:

[!code-aspxMain]

In the associated CSS class for the panel, define a nice background color and also set a fixed width for the panel:

[!code-cssMain]

Then, add the AnimationExtender to the page, providing an ID, the TargetControlID attribute and the obligatory runat="server":

[!code-aspxMain]

Within the <Animations> node, use <OnLoad> to run the animations once the page has been fully loaded. Instead of one of the regular animations, the <Condition> element comes into play. The JavaScript code provided as the value of the ConditionScript attribute is executed at runtime. If it evaluates to true, the animation is executed, otherwise not. The following markup provides two animations, each of them being executed in 50% of cases upon random. Since there may only be one animation within <OnLoad>, the two <Condition> animations are joined together using the <Sequence> element:

[!code-aspxMain]

Note that the less than sign (<) in the ConditionScript attribute must be escaped (). When you run this script, either no animation runs, or one of the two does, or both do.

The panel is fading out without resizing, so the second animation runs, the first one didn't

The panel is fading out without resizing, so the second animation runs, the first one didn't (Click to view full-size image)

[!div class="step-by-step"] Previous Next