I have a html button and a hidden field like this
<button id="btnperfdel" runat="server" type="button" class="btn btn-outline-secondary" onclick="myconfirm"></button>
<asp:HiddenField ID="myanswer" runat="server" ClientIDMode="Static" />
and this is my script that i want to run
<script type = "text/javascript">
function myconfirm() {
var myanswer = document.getElementById("myanswer")
if (confirm("Confirm Delete?")) {
myanswer.value = "Yes"
}
else {
myanswer.value = "No"
}
}
</script>
and this is my background code
Protected Sub btnperfdel_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnperfdel.ServerClick
If myanswer.Value = "Yes" Then
'some random things
Else
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('You clicked Cancel')", True)
End If
End Sub
But the javascript is not firing for onclick event. I tried onclientclick but if only returns alert 'You clicked cancel'.
What I have tried:
I tried other javascripts also, but all returns false value for onclientclick event and for onclick event, it doesn't doing anything. I'm novice in javascript. Please,Can someone help me out?