"
ASP.NET (snapshot 2017) Microsoft documentation and samples

Triggering an Animation in another Control (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. Generally, launching an animation is triggered by user interaction with the same control. It is however also possible to interact with one control and then animation another control.

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. Generally, launching an animation is triggered by user interaction with the same control. It is however also possible to interact with one control and then animation another control.

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]

   1:  <asp:ScriptManager ID="asm" runat="server" />

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

[!code-aspxMain]

   1:  <asp:Panel ID="panelShadow" runat="server" CssClass="panelClass">
   2:   ASP.NET AJAX is a free framework for quickly creating a new generation of more 
   3:   efficient, more interactive and highly-personalized Web experiences that work 
   4:   across all the most popular browsers.<br />
   5:   ASP.NET AJAX is a free framework for quickly creating a new generation of more 
   6:   efficient, more interactive and highly-personalized Web experiences that work 
   7:   across all the most popular browsers.<br />
   8:   ASP.NET AJAX is a free framework for quickly creating a new generation of more 
   9:   efficient, more interactive and highly-personalized Web experiences that work 
  10:   across all the most popular browsers.<br />
  11:  </asp:Panel>

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

[!code-cssMain]

   1:  <style type="text/css">
   2:   .panelClass {background-color: lime; width: 300px;}
   3:  </style>

In order to start animating the panel, an HTML button is used. Note that <input type="button" /> is favoured over <asp:Button /> since we do not want a postback when the user clicks on that button.

[!code-aspxMain]

   1:  <input type="button" id="Button1" runat="server" Value="Launch Animation" />

Then, add the AnimationExtender to the page, providing an ID, the TargetControlID attribute and the obligatory runat="server". It is important to set TargetControlID to the ID of the button (the element triggering the animation), not to the ID of the panel (the element being animated)

[!code-aspxMain]

   1:  <ajaxToolkit:AnimationExtender ID="ae" runat="server" TargetControlID="Button1">

Within the <Animations> node, place animations as usual. In order to make them change the panel, not the button, set the AnimationTarget attribute for every animation element within AnimationExtender. The value for AnimationTarget is the ID of the panel, of course. That way, the animations happen with the panel, not with the triggering button. Here is the AnimationExtender markup for this scenario:

[!code-aspxMain]

   1:  <ajaxToolkit:AnimationExtender ID="ae" runat="server" TargetControlID="Panel1">
   2:   <Animations>
   3:   <OnClick>
   4:   <Sequence>
   5:   <EnableAction Enabled="false" />
   6:   <Parallel>
   7:   <FadeOut Duration="1.5" Fps="24" AnimationTarget="Panel1" />
   8:   <Resize Width="1000" Height="150" Unit="px" 
   9:   AnimationTarget="Panel1" />
  10:   </Parallel>
  11:   </Sequence>
  12:   </OnClick>
  13:   </Animations>
  14:  </ajaxToolkit:AnimationExtender>

Note the special order in which the individual animations appear. First of all, the button gets deactivated once the animation runs. Since there is no AnimationTarget attribute in the <EnableAction> element, this animation is applied to the originating control: the button. The next two animation steps shall be carried out parallelly (<Parallel> element). Both have their AnimationTarget attributes set to "Panel1", thus animating the panel, not the button.

A mouse click on the button starts the panel animation

A mouse click on the button starts the panel animation (Click to view full-size image)

Previous Next



Comments ( )
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/web-forms/overview/ajax-control-toolkit/animation/triggering-an-animation-in-another-control-cs.htm
< THANKS ME>