Using the Animation Extender in AJAX Toolkit


V4 Ajax Tutorials
Server Intellect Cloud Hosting

Using the Animation Extender in AJAX Toolkit

In this tutorial, we will be looking at how to use the AnimationExtender in the AJAX Control Toolkit from Microsoft. This tutorial is aimed toward users of Visual Studio.NET 2008, but should work with 2005 providing the AJAX Extensions are installed.

This tutorial uses the Microsoft AJAX.NET Toolkit, which can be downloaded from the following link:
www.asp.net/Ajax/ajaxcontroltoolkit/

If you need help installing the Toolkit, please see this article.

In this tutorial, we will be explore using the AnimationExtender to utilize JavaScript to animate controls in our web application. The first thing we will need to do is to add a ScriptManager to our ASPX page, which will allow us to implement AJAX:

<asp:ScriptManager ID="SM1" runat="server" />

I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.

The next thing we will do is add an ASP.NET Panel control onto our page and drag an AnimationExtender from the Toolkit toolbox to our ASPX page:

.Animation1
{
position: absolute;
padding:3px;
border: solid 1px #000;
}

..

<form id="form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server" />
<br />
<asp:Panel ID="panel_Animated" runat="server" CssClass="Animation1">
Animation imminent.
</asp:Panel>
<br />
<cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="panel_Animated">
</cc1:AnimationExtender>
</form>

Notice that we have declared a CSS class for our Panel to use. If we do not make the Panel's position absolute, then we will not be able to manipulate its position on the page.
Now in order to actually animate the Panel, we are required to insert further parameters into the Extender, for example:

<cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="panel_Animated">
<Animations>
<OnLoad>
<Sequence>
<Move Horizontal="300" Duration="1" Fps="20" />
<FadeOut Duration="1" Fps="20" />
</Sequence>
</OnLoad>
</Animations>
</cc1:AnimationExtender>

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

We keep everything within the Extender tags, and notice that they are not all specified as attributes. There are a number of triggers we can use for animations, which include OnLoad, OnClick, OnMouseOver, OnMouseOut, OnHoverOver, and OnHoverOut. In this example we are using the OnLoad trigger so that when the page loads, the Panel will be animated 300 pixels horizontally over a period of 1 second. We are also able to set the number of frames per second with the Fps attribute.

Now when this page is run, the Panel will be animated as soon as the page is done loading. Now, if we wanted to animate on a button click, then we would use the OnClick trigger.
To do this, let's add a button and another panel to our ASPX page:

.Animation2
{
display:none;
position:absolute;
width:1px;
height:1px;
left:400px;
top:600px;
padding:3px;
border:solid 1px #000;
}

..

<asp:Button ID="btn_Animate" runat="server" Text="Animate" OnClientClick="return false;" />
<br />
<asp:Panel ID="panel_Animated2" runat="server" CssClass="Animation2">
Animation2 imminent.
</asp:Panel>
<br />
<cc1:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="btn_Animate">
<Animations>
<OnClick>
<Sequence AnimationTarget="panel_Animated2">
<EnableAction AnimationTarget="btn_Animate" Enabled="false" />
<StyleAction Attribute="display" Value="Block" />
<Parallel>
<FadeIn Duration="1" Fps="20" />
<Scale Duration="1" Fps="20" ScaleFactor="30.0" Center="true" />
</Parallel>
</Sequence>
</OnClick>
</Animations>
</cc1:AnimationExtender>

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

We create another CSS class for the new panel and notice we also change the OnLoad trigger as in the last example to OnClick. We are also required to set an AnimationTarget as our TargetControl is now the button, not the panel. The animation sequence is similar to the last, except we use Scale to increase the size of the Panel as well.

Our ASPX page looks something like this:

<style>
.Animation1
{
position: absolute;
padding:3px;
border: solid 1px #000;
}
.Animation2
{
display:none;
position:absolute;
width:1px;
height:1px;
left:400px;
top:600px;
padding:3px;
border:solid 1px #000;
}
</style>

..

<form id="form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server" />
<br />
<asp:Panel ID="panel_Animated" runat="server" CssClass="Animation1">
Animation imminent.
</asp:Panel>
<br />
<cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="panel_Animated">
<Animations>
<OnLoad>
<Sequence>
<Move Horizontal="300" Duration="1" Fps="20" />
<FadeOut Duration="1" Fps="20" />
</Sequence>
</OnLoad>
</Animations>
</cc1:AnimationExtender>
<br />
<br />
<asp:Button ID="btn_Animate" runat="server" Text="Animate" OnClientClick="return false;" />
<br />
<asp:Panel ID="panel_Animated2" runat="server" CssClass="Animation2">
Animation2 imminent.
</asp:Panel>
<br />
<cc1:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="btn_Animate">
<Animations>
<OnClick>
<Sequence AnimationTarget="panel_Animated2">
<EnableAction AnimationTarget="btn_Animate" Enabled="false" />
<StyleAction Attribute="display" Value="Block" />
<Parallel>
<FadeIn Duration="1" Fps="20" />
<Scale Duration="1" Fps="20" ScaleFactor="30.0" Center="true" />
</Parallel>
</Sequence>
</OnClick>
</Animations>
</cc1:AnimationExtender>
</form>

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 


Comments
sdasd said:

Interesting

Posted Feb 19, 2009 1:57 PM
Shailesh said:

Good one...thanks.

Posted Jul 8, 2009 4:31 PM
parikshit said:

hiii i have used animation extender but m geetting error

"aniamtion extender could not be set for property animation"

Posted Aug 17, 2009 2:37 AM
nitin said:

it's not workng in2008

Posted Oct 4, 2009 8:05 AM
SAHIL GULATI said:

Its a nice tutorial for understanding the workng of the animation extender.

But can you please provide modified tutorial in which there is one close icon located in the panel which gets populated on the click event of button on the extreme right hand side, and when we click on that icon that panel gets closed, and button will become enable again.

It would be much more resourceful

Regards:

SAHIL

Posted Feb 4, 2010 11:30 PM
Freelance SEO India said:

India’s leading Freelance SEO India services provider with main competency in Search Engine Optimization of websites.

Posted Dec 29, 2010 10:14 PM
dddd said:

dddd

Posted Mar 17, 2011 8:13 AM
shit said:

shit

Posted Apr 8, 2011 4:41 AM
Thanks said:

@SAHIL how about you do your own work, and stop trying to be sneaky and get someone else to do it.

Posted Jun 9, 2011 12:55 PM
www.outlet-louisvuitton.us said:

www.outlet-louisvuitton.us

Posted Aug 6, 2011 3:36 AM
rr said:

rerer

Posted Aug 22, 2011 7:00 AM
ffafa said:

niw fao niofa no faofano

Posted Dec 29, 2011 11:35 PM
Tanuj Kumar said:

Very informative post. Its really helpful for me and beginner too. Check out this link too its also having a nice post with wonderful explanation on Ajax Toolkit AnimationExtender Control in ASP.Net.....

mindstick.com/.../c0c7993d-c27e-4

Thanks

Posted Jan 3, 2012 4:53 AM

Leave a Comment