Animation Extender Example ASP.NET AJAX

13. October 2007

I found myself struggling on how to use the ASP.NET AJAX Control Toolkit Animation Extender.  I wanted to use a simple example on a website that was basically the example they give on the Toolkit website.  I wanted the user to click a link and it would “fly-out” a window to show more information.  I tried to follow the example online however, I found myself missing an important part to it…the CSS aspect of it.  I wanted to write a quick example of how to do this without you trying to read Microsoft’s source code and example online.

Step 1:  The following styles will need to be used in order for this to work.  I would recommend placing the classes into a stylesheet.

Step 2:  Place the DIV on your web page and the link button that we will use for our target control ID to activate the animation.  You will notice the OnClientClick=”return false;” this is so the link button does not post back.

Step 3:  Add the AnimationExtender to the web page


You'll notice in step 3 there are 2 animation extenders.  One is to show and move the DIV and the second is to close, move and hide the DIV.  The StyleAction tag in the second extender are very important because this is what sets the DIV back to the default view as if you just loaded the web page again.

I hope this has made it easier to use the animation extender.  The documentation online as to what the tags mean are very useful at:

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/AnimationReference.aspx

If anyone finds faults or problems in the code feel free to comment.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

AJAX.NET ,

Comments

Amit Kohli
2/25/2008 4:10:54 PM #
Hi John,
Its great your idea is really cool .... and working perfectly....
really everybody missing the important part of is ie CSS...

Hats Off Smile ------------>


Thanks,
Amit Kohli

John_M
2/26/2008 5:41:27 PM #
Thanks Amit, glad it worked well for you!

John M (author)
HershieSquirts
4/18/2008 4:57:22 PM #
This works great until I throw the css code into a external css file so I can use it across my website.  It's like the class' don't exist anymore, even though i'm still using the code verbatum from what you posted here.  Thoughts?
HershieSquirts
4/18/2008 5:27:39 PM #
Whoops, nevermind.  I have it nested in another class.  dumbass! Frown
John_M
4/18/2008 6:17:09 PM #
Glad you got it working!
dawg
4/30/2008 4:13:32 AM #
Wow, this is great.  I've been trying to get an effect like this going for a while now, and your code worked on the first try.  Thank you...thank you...

I have implemented this in a gridview with the lnkBtnColHelp appearing in the first column of each row.  The effect works great however I was hoping someone might be able to help me with the code so the popup can open and close using the same link button or even an image or image button.

Thanks again for the excellent method.
dana
6/23/2008 10:46:16 AM #
This works great.

I do have a question though - is it possible to show dynamic text and not static code in the div?
When clicking the link (or button) i want to build the text on the server side and show it.
How can I do that?

Thanks,
Dana
John_M
6/23/2008 9:56:41 PM #
Dana,

That is a good question, I have yet to try that or have a need for it.  The link below shows how you can call a web service from javascript.  This may help you out since when you click the button or link it runs client-side javascript.

www.codeproject.com/KB/ajax/WebServiceCallApp.aspx

If I do find something I'll let you know.
Ravi Kiran
7/1/2008 7:05:34 AM #
Hi this post is really helpful as I have strugled to do the same.. Million thanks... Smile
Janak
10/1/2008 11:20:24 AM #
I tried you code. Everything is fine untill you do the following.
1) click the link to open the animations.
2) click the lik again (while the animation is open). Apparently, <EnableAction Enabled="false"></EnableAction> does not fire on link buttons. Any solutions for it?
10/2/2008 4:57:41 PM #
Janak:
I struggled with the same problem myself, and I found that the most simple solution did the trick.
When you're animating your flyoutdiv, also set "<StyleAction AnimationTarget="yourButton" Attribute="display" Value="none"/>" amongst the other StyleAction-attributes, and ofcourse the same thing around when you're closing your flyoutdiv, but instead you set "<StyleAction AnimationTarget="yourButton" Attribute="display" Value="block"/>"

It hides your button as soon as you click it, and displays it again at the same time you close your div. Atleast it fits my needs perfectly!

And btw, John M, thx alot for this one, it saved me loads of headache Tong
John_M
10/2/2008 7:38:22 PM #
Daniel, thank you so much for providing some feedback on this one.  I've been pretty tied up so it's been tough to get on here to send a response.  

Also, no problem on providing this example, I had a big headache when trying to figure it out myself.  The docs weren't that great on it.  Thanks again Daniel
joep
10/7/2008 4:28:23 PM #
Great! thank you
10/11/2008 8:02:26 AM #
Iam working asp.net 2.0 I have used AnimationExtedet but it should not any onclick events or sequence tags with in animation tag
10/11/2008 8:05:11 AM #
please replay to my quation
John_M
10/13/2008 4:16:46 PM #
trimurthy,

Sorry for the late response, been pretty wrapped up. I apologize but I'm having trouble understanding what you are asking. Do you want to use it without any click events and without any sequence tags? If so are you looking for example with that? Please let us know.

Thanks,
John M (author)
Raman
11/4/2008 12:10:15 PM #
Hello....
I have tried this code..and this code is working perfectly but i want a code  as follows:

I have taken a textbox near the likn button.

I want to tell u in a very simple condition:

if textbox has text "Raman" only then flyout works other wiese it will display nothing.

Please tell me about this problem...



Xavier Averbouch
12/2/2008 1:05:23 PM #
just GREAT!!!!!
manoj jain
12/16/2008 10:34:25 AM #
that great thanks yar
ashwin
1/25/2009 4:12:19 PM #
hi... i tried fade animation and i am not able to execute it . following error occurs...  "Animation on TargetControlID="panel2" uses property AjaxControlToolkit.AnimationExtender.onload that does not exist or cannot be set"   ... please can i know how to rectify this??
1/26/2009 1:24:45 AM #
ashwin,

I'm not sure what code you are using so I can't be too much of help.  Make sure you targetID's are correct and your ID's are correct for what you are trying to animate.  Also, I haven't tried the onload method for animation so you may want to make sure that is even a valid method for the extender.

John M (author)
Sims
1/27/2009 5:05:10 AM #
Hi John,

Great post. The code runs fine on Firefox. But doesnt on Internet Explorer 7 ,

I have a feeling its to do with the Javascript code for the Animation Extender, though I could be wrong.

Would you be able to spot the difference , as I have played around with the values in the source yet to no avail.

Best Regards
1/27/2009 10:08:24 PM #
Sims,

I have checked this in IE 7 and it seemed ok.  Are you using different code?

John M
Sims
1/29/2009 4:07:28 AM #
Hi John, I managed to get it working.

Just another question, I did a different version of this except instead of using the onclick property, I used the (hover over/mouse over), (hoverout/mouseout) version over an image. where the user places the mouse over the image and the message flys in and when the mouse is off the image it flies out.

Except one problem. - When I do this to quickly - in other words place the mouse pointer over the image then quickly take it off it then place it on the image again, the position of where the fly in message changes. If you have some time to evaluate my code , it would be greatly appreciated. Thanks for your reply earlier too.

<body>
    <form id="form1" runat="server">
    <div>
            <asp:ImageButton ID="myone" runat="server" Height="235px"
            ImageUrl="~/Images/whitehaven.jpg" Width="217px" OnClientClick="return false;" />


            <div id="moveMe" class="flyOutDiv">
            <div style="float:right;">
            
            <br />
     <p>
        The Whitsundays
     </p>      
     </div>
                      
</div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="myone">
        <Animations>
        <OnHoverOver>
        <Sequence>
        <EnableAction Enabled="true"></EnableAction>
         <StyleAction AnimationTarget="moveMe" Attribute="display" Value="block"/>
          <Parallel AnimationTarget="moveMe" Duration=".5" Fps="30">
           <Move Horizontal="200" Vertical="50"></Move>
           <FadeIn/>
           </Parallel>
           <Parallel AnimationTarget="moveMe" Duration=".5">
        <Color PropertyKey="color" StartValue="Blue" EndValue="Blue" />
      <Color PropertyKey="borderColor" StartValue="Blue" EndValue="Blue" />
         </Parallel>
       </Sequence>
        </OnHoverOver>
        </Animations>
        </cc1:AnimationExtender>
        <cc1:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="myone">
        <Animations>
        <OnHoverOut>
                           <Sequence AnimationTarget="moveMe">
                        <Parallel AnimationTarget="moveMe" Duration=".7" Fps="20">
                            <Move Horizontal="-200" Vertical="-50"></Move>
                            <Scale ScaleFactor="0.05" FontUnit="px" />
                            <Color PropertyKey="color" StartValue="#FF0000" EndValue="#666666" />
                            <Color PropertyKey="borderColor" StartValue="#FF0000" EndValue="#666666" />
                            <FadeOut/>
                        </Parallel>

                        <StyleAction Attribute="display" Value="none"/>
                        <StyleAction Attribute="height" Value=""/>
                        <StyleAction Attribute="width" Value="400px"/>
                        <StyleAction Attribute="fontSize" Value="14px"/>
                        <EnableAction AnimationTarget="myone" Enabled="true" />

                    </Sequence>
        </OnHoverOut>
        </Animations>
        </cc1:AnimationExtender>
    </div>
    
    </form>
</body>

Best Regards
2/4/2009 11:31:13 AM #
bncv
TimB
3/5/2009 4:35:07 AM #
The fade out animation doesn't work on FF 3.0 and may cause the text to overflow from the original div, which is really a shame.
3/5/2009 6:51:59 PM #
Tim,

Thanks for the comment.  That is a shame.  Do you have any work arounds?  I really need to find the time to come back to this and see what can be improved.  I've been busy working on some silverlight 2 projects and our product Club Dynamix.  Let us know if you do.  Any suggestions on what you may want to see on this blog let me know as well. Thanks!

John M
Madison
3/6/2009 9:24:33 PM #
Hi,
The first click is working fine, but when I closed it and click the button to show it again, it changed the font-size and position?
Anybody had this problem?

Madison
2009.03.06
Sheethal
4/7/2009 1:16:42 AM #
Thanks a lot for this demo. I was struggling with the animation control.
sudhakar
5/21/2009 2:10:06 PM #
Hi
Thanks a lot . It's very nice and easy to learn.I am a biggner to AJAX.
jai
5/26/2009 10:53:19 PM #
hi,

i got the animation extender with little sample message with "X" button on the right top. but, when clicked on "X" button, nothing happens!. Am I missing someting?

jai
Brijesh
6/22/2009 9:26:24 AM #
hi, this is great article but i wana to display gridview data into that so what steps need to follow.. plz help me its urgent
Srini
7/16/2009 5:24:33 PM #
Thanks Jon it's working gr8 Smile
7/21/2009 12:53:05 PM #
Jon thansk it's working to me too
parikshit
8/26/2009 12:41:28 PM #
hiiii.......
            its realy gud.its workin f9.it is wat exactly i want.i jst want to ask that is it necessary to use div tag.cant we do without it......
i tried but it gave error.....
cc1:Animationextender can not be set on property animations....
abhishek
8/26/2009 1:55:17 PM #
Thanks dude . Nice example . Thanks
Girish
9/7/2009 5:28:02 AM #
Hi John,

Thanks for post dude. it works...really looking forward for ur new post and samples..please let me know.

Girish
jasbeer
10/21/2009 1:17:07 PM #
hey friend thanks a lot for the code.....i was facing a big problem in this control..but as soon i got this i am able to run the animation control....but i am facing a problem as i m a beginner in asp.net.
The problem is that when i run the application..At the very first time div is displayed at one place...and if i again click on the link button then the div changes its position..so kindly tell me how to fix the div at a single place even after clicking the link many times....
when i load the page again then its wrking fine but if i continues to work on the same page then the div changes its position...
plzzz help me....
2/5/2010 8:25:41 AM #
Hi John,

Thanks for posting such a wonderful code that clearly explain the working of ajaxtoolkit animation extender,

Looking forward for more resourceful code from your side

Nice work!!!!!!!!!!
Steve C
3/10/2010 3:37:34 PM #
John,
Very nice!! Looked all over the web and this is great on how you explained etc. The AJAX is somewhat confusing in what version to use and what toolbox etc. but after studying it for a few days I think I got it, got your code to work and it is slick, THANKS!
Question:
Do you if there is a way to disable the Click Here after it is clicked, because if you continue to click it the animation pushes the pop around per the Horizontal and Vertical <MOVE> offsets.
Thanks for your help, much appricated.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading