I have followed several solution suggestions for this problem but nothing is working properly. My desired outcome is to fire off a JavaScript validation function before executing the C# code behind method upon successful validation return of true. OnClick should be followed after the javascript OnClientClick operation.
I have tried suggestions from this thread:
Executing OnClick code behind method after returning true from OnClientClick javascript function
as well as this thread:
Executing OnClick code behind method after returning true from OnClientClick javascript function
This is my current layout:
<asp:Button ID="btnAdd" runat="server" AutoPostBack="true" OnClick="btnAdd_Click" OnClientClick="btnAdd_Click(this, event);" Text="Add" UseSubmitBehavior="false"/>
function btnAdd_Click(sender, args) {
if(confirm('Do you want to do a server trip?'))
{
return true;
}
else
{
return false;
}
}
I have also tried:
<asp:Button ID="btnAdd" runat="server" AutoPostBack="true" OnClick="btnAdd_Click" OnClientClick="if (!Confirm()) return false;" Text="Add" UseSubmitBehavior="false"/>
function Confirm() {
return confirm("Are you sure?");
}
What i am seeing is JavaScript is firing off every time. Debugging JS proves that it is returning true back to my solution, so the OnClick should get hit. I have a break point in my click event on the code behind but it never gets hit. Is there a site setting or something preventing this?
Help is much appreciated. Thanks in advance.