I m posting my code and HTML build for the button, I tried postback, submit and other functions,, none worked. I m running the my elements in update panel
I know my problem is in returning and employing the boolean val from AJAX call
Please help
A scientist shouldn’t be asked to judge the economic and moral value of his work. All we should ask the scientist to do is find the truth and then not keep it from anyone
“Arthur Kornberg”
A scientist shouldn’t be asked to judge the economic and moral value of his work. All we should ask the scientist to do is find the truth and then not keep it from anyone
“Arthur Kornberg”
I tried your code but that did not work on my end too. I am not quite sure, what could be the issue. However, one thing I noticed that your Ajax call needs to be async: false, otherwise button click will be executed right after user has clicked and it will
not wait for ajax call result. Here is a sample code on similar scenario that is working on my end, you may do required modification based on your coding scenario:
[WebMethod]
public static bool AuthUsrEntry(string Usrname, string Pw)
{
//-- i am just passing true here to check if click event executes or not
return true;
}
protected void cmdlogin_Click(object sender, EventArgs e)
{
//-- button click event
}
hope that helps./.
नमस्ते,
[KaushaL] BlogTwitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
the function returns the boolean value from the web service beautifully but even with true callback the button does not fire
could it be JSON2 call?
A scientist shouldn’t be asked to judge the economic and moral value of his work. All we should ask the scientist to do is find the truth and then not keep it from anyone
“Arthur Kornberg”
function AuthUsr() {
var retResult = false;
var obj = {};
obj.Usrname = $.trim($("#username").val());
obj.Pw = $.trim($("#password").val());
$.ajax({
type: "POST",
url: "../../SessionService.asmx/AuthUsrEntry",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
//debugger;
var serresp = r.d
if (serresp == false) {
//MsgNotify('Error', '', 'Invalid Password!', '', '')
retResult = false;
}
else
retResult = true;
},
error: function (data) {
retResult = false;
}
});
return retResult;
}
function calltest() {
var r = AuthUsr()
alert(r)
if (r == false) {
return false
}
else {
return true;
__doPostBack('cmdlogin', '')
}
}
A scientist shouldn’t be asked to judge the economic and moral value of his work. All we should ask the scientist to do is find the truth and then not keep it from anyone
“Arthur Kornberg”
r.d returns true but the whole function returns false!
That might be because you did not made async: false for Ajax call. It is really important, otherwise retResult will be returned just as it is (which is actually set to false initially if you see), without taking into considering value being returned from
Ajax call. Notice async: false in my earlier post and do that change accordingly. That should resolve the issue.
A scientist shouldn’t be asked to judge the economic and moral value of his work. All we should ask the scientist to do is find the truth and then not keep it from anyone
“Arthur Kornberg”
you are correct, once i make it sync the value comes back in real time but i want to avoid sync jq, any way around it?
A scientist shouldn’t be asked to judge the economic and moral value of his work. All we should ask the scientist to do is find the truth and then not keep it from anyone
“Arthur Kornberg”
I have already posted async: false in an example that I posted in my first post in this thread. However, I did not understand what you mean by "avoid sync jq". can you elaborate?
नमस्ते,
[KaushaL] BlogTwitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
117 Points
241 Posts
ASP button does not fire event after return true from JS function
Mar 07, 2017 07:26 AM|Embryologist|LINK
I m posting my code and HTML build for the button, I tried postback, submit and other functions,, none worked. I m running the my elements in update panel
I know my problem is in returning and employing the boolean val from AJAX call
Please help
“Arthur Kornberg”
All-Star
15186 Points
3888 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 07:31 AM|raju dasa|LINK
Hi,
I think, in the above code, # is not required.
check this site: http://stackoverflow.com/questions/3591634/how-to-use-dopostback
rajudasa.blogspot.com || rajudasa-tech
Member
117 Points
241 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 07:34 AM|Embryologist|LINK
Thanks for the prompt reply
I did both
did not work
“Arthur Kornberg”
All-Star
31362 Points
7055 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 07:54 AM|kaushalparik27|LINK
I tried your code but that did not work on my end too. I am not quite sure, what could be the issue. However, one thing I noticed that your Ajax call needs to be async: false, otherwise button click will be executed right after user has clicked and it will not wait for ajax call result. Here is a sample code on similar scenario that is working on my end, you may do required modification based on your coding scenario:
hope that helps./.
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
Member
117 Points
241 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 08:03 AM|Embryologist|LINK
Thanks for the elaborative response
the function returns the boolean value from the web service beautifully but even with true callback the button does not fire
could it be JSON2 call?
“Arthur Kornberg”
Member
117 Points
241 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 08:18 AM|Embryologist|LINK
r.d returns true but the whole function returns false!
“Arthur Kornberg”
All-Star
15186 Points
3888 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 08:21 AM|raju dasa|LINK
Hi,
AFAIK, Button doesn't waits for ajax callback return. it gets return immediately.
You need a logic to work around.
rajudasa.blogspot.com || rajudasa-tech
All-Star
31362 Points
7055 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 08:35 AM|kaushalparik27|LINK
That might be because you did not made async: false for Ajax call. It is really important, otherwise retResult will be returned just as it is (which is actually set to false initially if you see), without taking into considering value being returned from Ajax call. Notice async: false in my earlier post and do that change accordingly. That should resolve the issue.
Edit: Pasting an informative link: What does "async: false" do in jQuery.ajax()?
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
Member
117 Points
241 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 08:25 PM|Embryologist|LINK
Do you have an example please
“Arthur Kornberg”
Member
117 Points
241 Posts
Re: ASP button does not fire event after return true from JS function
Mar 07, 2017 08:27 PM|Embryologist|LINK
you are correct, once i make it sync the value comes back in real time but i want to avoid sync jq, any way around it?
“Arthur Kornberg”
All-Star
31362 Points
7055 Posts
Re: ASP button does not fire event after return true from JS function
Mar 08, 2017 06:08 AM|kaushalparik27|LINK
I have already posted async: false in an example that I posted in my first post in this thread. However, I did not understand what you mean by "avoid sync jq". can you elaborate?
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
All-Star
45489 Points
7008 Posts
Microsoft
Re: ASP button does not fire event after return true from JS function
Mar 08, 2017 09:09 AM|Zhi Lv - MSFT|LINK
Hi Embryologist,
As KaushaL said, you could set the Ajax async to false. Besides, I think you could also try to add a hidden button in your page.
Then use js code to click it when the WebMethod return true.
For example:
Best regards,
Dillion