Animation Extender Example ASP.NET AJAX

October 12, 2007 16:13 by John M

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.

.flyOutDiv
{
     display: none;
     position: absolute;
     width: 400px;
     z-index: 3;
     opacity: 0;
     filter:(progid:DXImageTransform.Microsoft.Alpha(opacity=0));
     font-size: 14px;
     border: solid 1px #CCCCCC;
     background-color: #FFFFFF;
     padding: 5px;
}

.flyOutDivCloseX
{
 background-color: #666666;
 color: #FFFFFF;
 text-align: center;
 font-weight: bold;
 text-decoration: none;
 border: outset thin #FFFFFF;
 padding: 5px; 
}

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.

<asp:LinkButton ID="lnkBtnColHelp" runat="server" Text="Click Here" OnClientClick="return false;" />

<div id="moveMe" class="flyOutDiv">
  <div style="float:right;">
 <asp:LinkButton ID="lnkBtnCloseColHelp" runat="server" Text="X" OnClientClick="return false;" CssClass="flyOutDivCloseX" />
  </div>
<br />
     <p>
        some content here for whatever text
     </p>                         
</div>

Step 3:  Add the AnimationExtender to the web page

<ajaxToolKit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="lnkBtnColHelp">
            <Animations>
                <OnClick>
                    <Sequence>
                        <EnableAction Enabled="false"></EnableAction>
 
                        <StyleAction AnimationTarget="moveMe" Attribute="display" Value="block"/>
                        <Parallel AnimationTarget="moveMe" Duration=".5" Fps="30">
                            <Move Horizontal="-350" Vertical="50"></Move>
                            <FadeIn Duration=".5"/>
                        </Parallel>
                        <Parallel AnimationTarget="moveMe" Duration=".5">
                             <Color PropertyKey="color" StartValue="#666666" EndValue="#FF0000" />
                            <Color PropertyKey="borderColor" StartValue="#666666" EndValue="#FF0000" />
                        </Parallel>
                    </Sequence>
                </OnClick>
            </Animations>
       
        </ajaxToolKit:AnimationExtender>
       
        <ajaxToolKit:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="lnkBtnCloseColHelp">
       
            <Animations>
                <OnClick>
                    <Sequence AnimationTarget="moveMe">
                        <Parallel AnimationTarget="moveMe" Duration=".7" Fps="20">
                            <Move Horizontal="350" 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="lnkBtnColHelp" Enabled="true" />
                    </Sequence>
                </OnClick>
            </Animations>
       
  </ajaxToolKit:AnimationExtender>


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.


Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

February 25. 2008 07:10

Gravatar

Hi John,
Its great your idea is really cool .... and working perfectly....
really everybody missing the important part of is ie CSS...

Hats Off :) ------------>


Thanks,
Amit Kohli

Amit Kohli

February 26. 2008 08:41

Gravatar

Thanks Amit, glad it worked well for you!

John M (author)

John_M

April 18. 2008 07:57

Gravatar

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

April 18. 2008 08:27

Gravatar

Whoops, nevermind. I have it nested in another class. dumbass! :(

HershieSquirts

April 18. 2008 09:17

Gravatar

Glad you got it working!

John_M

April 29. 2008 19:13

Gravatar

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.

dawg

June 23. 2008 01:46

Gravatar

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

dana

June 23. 2008 12:56

Gravatar

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.

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

If I do find something I'll let you know.

John_M

June 30. 2008 22:05

Gravatar

Hi this post is really helpful as I have strugled to do the same.. Million thanks... :)

Ravi Kiran

October 1. 2008 02:20

Gravatar

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?

Janak

October 2. 2008 07:57

Gravatar

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 :P

Daniel Modig

October 2. 2008 10:38

Gravatar

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

John_M

October 7. 2008 07:28

Gravatar

Great! thank you

joep

October 10. 2008 23:02

Gravatar

Iam working asp.net 2.0 I have used AnimationExtedet but it should not any onclick events or sequence tags with in animation tag

trimurthy

October 10. 2008 23:05

Gravatar

please replay to my quation

trimurthy

October 13. 2008 07:16

Gravatar

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)

John_M

November 4. 2008 03:10

Gravatar

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...



Raman

Add comment


(Will show your Gravatar icon)  

  Country flag




Live preview

November 21. 2008 06:43

Gravatar