ASP.Net Confirm box issue

前端 未结 2 1100
北恋
北恋 2021-01-17 01:51

In my asp.net application I have used JavaScript confirm box for user confirmation. Here is the code:

EDIT :



        
相关标签:
2条回答
  • 2021-01-17 01:54

    Simple solution use javascript and call OnClientClick

    <script type="text/javascript">
            function confirm() {
               if (confirm('This Contract Have a Pre-Renewed,Please Delete that Contract First')) {
                    return true;
                }
                else {
                    return false;
                }
            }
          </script>     
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="return  
     confirm()"/>
    
    0 讨论(0)
  • 2021-01-17 02:11

    By using javascript confirm method you only decide, whether you want to continue or not - so it is ok that your Button1_Click method is called only when user clicks ok.

    What you trying to do is quite different. I would suggest to get rid of ASP.NET Button control and use "common" HTML link like:

    <a href="#" id="decideLink">Click me</a>
    

    And then in javascript

    document.getElementById('decideLink').onclick = function()
    {
        if(proceed) {
            // do something here
        } else {
            // do something different
        }
    }
    

    To call code-behind method from javascript, check this article about calling web methods from javascript

    0 讨论(0)
提交回复
热议问题