views:

36

answers:

2

I've read plenty of good blog posts on integrating jquery with ASP.NET web forms to utilize the data access capabilities, but I'm curious to know how easy it would be to use some of jquery's animation capabilities before a postback. I can think of two good examples:

1) When I click on a asp:button, animate a div, but then do a regular postback when the animation is finished (or complete the animation after the postback?).

2) When I click on a linkbutton in a gridview, fade out the gridview row, then do the regular postback in the linkbutton's onclick event.

I'm not aware of a solution to this. Everything I've tried has either run the postback before the animation even starts, or runs the animation but then you need to execute the postback in javascript (yuck).

A: 

I've used jQuery many times to hide a button before a postback so I don't get the double click problem. What exactly is your problem that you need a solution to -- this is not hard.

Hogan
+3  A: 

yes offcourse you can do that.

say for example we take a button to do some postback

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

OnClick Event - cause the postback to be processed on serverside

but if you also define a OnClientClick event and call any javascript function with return value to the call. It will decide the post back after the javascript function is executed.

For eg:

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return DoJqueryAnimations();" />

In above example - DoJQueryAnimations() is a js function. we call it with a "return:"

so when the function is called and decides what to return. And the postback will wait for the client function to give the value - true(do postback) / false (no post back)

in javascript function u do the animation and return true

eg:

function DoJqueryAnimations()
{
   //do some animations here or call other javascript function
    return true;
}

hope this helps,

Regards, J'Sinh

J Sinh
I've actually tried to do exactly that. The problem is that the jquery animation does not complete it's action before the javascript function returns true and the postback occurs.
Robbo
well did tried that with sliding animations and you are true. I wont wait for the animation to complete. Well in most of the animate functions you can provide an callback function in the method where it will call the callback function once the animation is complete u can used that wisely to complete your goal >> here is an example >>> http://api.jquery.com/slideUp/#speedcallback where it uses duration as first argument and "callback" function as second argument to do something after the animation have completed. Hope this will help you solve your problem
J Sinh