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

Executing Animations Using Client-Side Code (VB)

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. The animation execution may also be triggered using custom client-side 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. The animation execution may also be triggered using custom client-side 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]

   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>

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

[!code-aspxMain]

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

Within the <Animations> node, use <OnClick> to run the animations once the user clicks on the panel. Add two animations to be executed parallelly:

[!code-xmlMain]

   1:  <Animations>
   2:   <OnClick>
   3:   <Parallel>
   4:   <FadeOut Duration="1.5" Fps="24" />
   5:   <Resize Width="1000" Height="150" Unit="px" />
   6:   </Parallel>
   7:   </OnClick>
   8:   </Animations>
   9:  </ajaxToolkit:AnimationExtender>

For the sake of demonstration, this animation (and any other animation created using the Control Toolkit) is executed using JavaScript code, once the page runs. First of all we need access to the AnimationExtender control. The ASP.NET AJAX library provides the $find() function for this task:

[!code-csharpMain]

   1:  var ae = $find("ae");

The AnimationExtender control exposes a rich API, including methods with names identical to the event handlers used in the XML markup: OnClick(), OnLoad(), and so on. For instance, a call of the OnClick() method executes the animation within the <OnClick> element of the AnimationExtender control:

[!code-javascriptMain]

   1:  ae.OnClick();

Here is the complete client-side JavaScript code that emulates the click on the panel once the page has been fully loaded note that the pageLoad() function name is used which is called by ASP.NET AJAX once the page and all included JavaScript libraries have been loaded.

[!code-htmlMain]

   1:  <script type="text/javascript">
   2:   function pageLoad() {
   3:   var ae = $find("ae");
   4:   ae.OnClick();
   5:   }
   6:  </script>

The animation runs immediately, without a mouse click

The animation runs immediately, without a mouse click (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/executing-animations-using-client-side-code-vb.htm
< THANKS ME>