Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i have a problem in one of my code.

i have a button which have server side and client click event.

on client click i call a java script function to validate some data and also call jquery ajax post method to check some flag from the database. previously this jquery ajax method was not there and everything works fine but as i add this method my server side button click stop working. may be bacause of the post method but i am not sure. can some one please help me here is my code .


ASP.NET
<asp:Button ID="btnSave"  runat="server" Text="Save" class="button" onclick="btnSave_Click" OnClientClick="Page_ClientValidate(); return CompareDate(); "  />


comparedate () is my javascript function and also have one more function inside compare date which is jquery ajax function.

JavaScript
 function CompareDate() {
var flag =falsel
//some validation code
//(this will set the flag based on some condition)
//ajax post method 
//(here again some data is compared)
//based on the last value of flag it will return true or false. n
}


now my function return true but server side method of the button click not working.
Posted
Comments
Dimitri Nostarik 5-Aug-14 4:01am    
Could you please describe this more in more detail? Javascript runs on your client, not on your server. You can use the Javascript to get validation from the server though.

Without your code, we can not help you.
ravikhoda 5-Aug-14 4:06am    
well the code is very long but the main logic is on client click event i check some validation and set flag variable. and now if the flag is true i return true which will execute the server side button click event. now after adding the jquery ajax post method inside the compare date function even though my function return true my server side button click event not firing.
Dimitri Nostarik 5-Aug-14 4:08am    
Once again, if you want us to help you fix an error or bug, we first need to see your code.
BulletVictim 5-Aug-14 4:25am    
Try adding __doPostBack('btnSave', 'btnSave_Click'); at the end of function CompareDate().

This will trigger a postback on the page executing the server side code on the button_click event

1 solution

return true; value from CompareDate() function. This will let the page to post-back.
 
Share this answer
 
Comments
ravikhoda 5-Aug-14 7:59am    
nop this was not worked. this code was always there but the main issue was the post method of jquery ajax. i have used the callback function and it started working.
Strikerzz Arut 5-Aug-14 8:18am    
Is this issue fixed? and you can validate the page inside the compareDate function. Even if you return true the Page_ClientValidate();will not let u to perform the postback until/unless the page.isvalid becomes true.
ravikhoda 5-Aug-14 23:53pm    
Hi, thanks for your info. yeah i got my issue fixed by putting async : false in my ajax jquery function. it was now do not allow any background code to run until my ajax request complete.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900