简体   繁体   中英

In asp.net button onclick and onclientclick not working for alert and confirm methods in javascript

<asp:Button ID="btnSubmit" runat="server" style=" float:left"  Text="Submit" `OnClientClick="submitRequest();" onclick="btnSubmit_Click" TabIndex="8"/>`

and

<script type="text/javascript">
function submitRequest() {
            var hdn_YearlyAvailableFund = parseFloat("<%= hdnYearlyAvailableFund.Value %>");

            var hdn_Amount = parseFloat("<%= hdnAmount.Value %>");
            var hdn_QueryString = "<%= hdnQueryString.Value %>";
            var approve = document.getElementById("<%=rdbApprove.ClientID %>");
            var check = approve.checked;
            if (hdn_QueryString.toString() == 'X') {
                if (approve.checked == true) {
                    if (hdn_YearlyAvailableFund < hdn_Amount) {
                        alert('Yearly available fund is less than Requested Amount, Cannot approve...!')                           
                    }
                    else {
                        if (confirm('Are you sure want to update this request?'))
                            document.getElementById('<%= btnSubmit.ClientID  %>').click();
                    }
                }
            }
            else {
                if (confirm('Are you sure want to update this request?')) {
                    document.getElementById('<%= btnSubmit.ClientID  %>').click();
                }
            } 
        }

    </script>

Here in my code for alert and confirm methods are not working together.

i request to give me a solution. Thanks in advance.

Try adding the term return ; you must return a value:

return confirm('Are you sure want to update this request?')

Also works on OnClientClick .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM