0

In my code I have a asp button which has OnClientClick event like this

OnClientClick="return validateAndSend();"

This function calls another function where it posts message on facebook and then after that call it returns a boolean value something like this

function validateAndSend()
{
   //some processing

   postOnFacebook();

   return validateResult;
}

Now the problem is when I click that button, it kind of not execute postOnFacebook function and returns validateResult that makes my page get posted back.

I want it to first completely run postOnFacebook function and waits for its completion and then return validateResult

However, when I put breakpoint on postOnFacebook() call line on firebug the function gets properly called.

I am not getting why this is happening, any idea?

Pawan Nogariya
  • 8,330
  • 12
  • 52
  • 105
  • Probably because `postOnFacebook` makes an Ajax request. Have a look at [How to return the response from an AJAX call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) to learn about the difference between asynchronous and synchronous code (and how to work with it). – Felix Kling Aug 03 '13 at 20:23

1 Answers1

-1

It most probably looks like a problem with your postOnFacebook() function. It may have Ajax that is not being handled properly (thats what I meant by check it).

woofmeow
  • 2,370
  • 16
  • 13
  • Could anybody tell me why the downvote ? Given the information that is probably all that is all one could possibly say .. since the function code is not given as well !! Trying ot help doesn't count I guess ! We are programmers here not magicians who can answer without the code !! – woofmeow Aug 03 '13 at 20:41
  • Well adding a comment requires "50 reputation" which at this point in time I do not have. Anyway sad seeing people downvote a genuine attempt to help :( on such a nice platform like stackoverflow !! – woofmeow Aug 03 '13 at 20:54
  • Yeah, I know about the rep limit for comments, but still it should maybe be a comment. The down vote is to let you know that you need to improve your answer. Though, it is bad that the down-voter didn't give some constructive feedback. But don't give up, learn from it =) – Mario S Aug 03 '13 at 21:00
  • Well I don't think there is anything to learn from it given the limitation of the rep limit. Don't think I could have done or can do different the limit exists . Anyways who cares about such behaviour lol – woofmeow Aug 03 '13 at 21:16
  • 1
    I downvoted it. Why? Because at the time I cast the vote, your were basically saying "there must be a problem in your code, have a look at it". How is that helpful? The OP already knows that there is a problem, otherwise they would not ask. Even your current "answer" does not seem to be very useful. What do you mean by *"Ajax that is not being handled properly"*? What does the OP have to do to "handle it properly? If you cannot comment yet, then **wait** until you can. I totally agree that there is not enough information to solve the problem and that's why there cannot exist an "answer". – Felix Kling Aug 03 '13 at 22:13
  • Correction 1)I never vaguely said "there must be a problem in your code,have a look at it" I always said that there was a problem with the `postOnFacebook()` fn,followed by "Please check your code".2)If I dont have the point to "comment" then obviously I will do the best I can to help the person questioning.3)Stackoverflow is all about people getting stuck and learning fast so I can't *wait*4)If you think the question can't have an "answer" then downvote the question instead of downvoting the "answer" when someone trying to help the person who asked the question.Get your facts right please! – woofmeow Aug 03 '13 at 22:47