I have this scenario. This is the front end asp:button component.
<asp:Button ID="btnNewsAdd" runat="server" Text="Edit current news item" OnClientClick="return Confirm();" OnClick="btnNewsAdd_Click" UseSubmitBehavior="false"/>
This is the Javascript:
<script type="text/javascript">
function Confirm() {
var result = window.confirm('Are you sure?');
if (result == true)
return true;
else
return false;
}
</script>
The user should click on the "btnNewsAdd" button, the Javascript should be fired and a dialog box with yes or no options pops up. Clicking yes will return true and no will return false. If true is returned the ASP.Net method in the backend: btnNewsAdd_Click should fire. It was working up until 15 mins ago. When debugging, the JS steps over the return true line and headsinto javascript files that I did not create myself; however, the backend method does not fire.
I noticed that in the Sources section, the HTML converted to the below. As one can see the OnClick and OnClientClick automatically merged into OnClick. This was automatic and I don't know if it could be the problem or part of it.
<input type="button" name="ctl00$MainContent$btnNewsAdd" value="Edit current news item" onclick="return Confirm();__doPostBack('ctl00$MainContent$btnNewsAdd','')" id="MainContent_btnNewsAdd" />
I have literally spent a whole day trying to get around it. At a certain point it was working and it just stopped working without having changed anything. Any suggestions appreciated.