【问题标题】:In asp.net button onclick and onclientclick not working for alert and confirm methods in javascript在 asp.net 按钮中,onclick 和 onclientclick 不适用于 javascript 中的警报和确认方法
【发布时间】:2020-09-01 05:12:01
【问题描述】:
<asp:Button ID="btnSubmit" runat="server" style=" float:left"  Text="Submit" `OnClientClick="submitRequest();" onclick="btnSubmit_Click" TabIndex="8"/>`

<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>

在我的代码中,警报和确认方法没有一起工作。

我请求给我一个解决方案。提前致谢。

【问题讨论】:

    标签: javascript asp.net onclick onclientclick


    【解决方案1】:

    尝试添加术语return;你必须返回一个值:

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

    也适用于OnClientClick

    【讨论】:

    • 是的,但是 onclientclick 它应该调用整个函数 submitRequest(),我无法继续
    猜你喜欢
    • 2012-12-13
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 2016-03-15
    相关资源
    最近更新 更多