How to show a message box in an ASP.NET page?

前端 未结 8 629
青春惊慌失措
青春惊慌失措 2020-12-20 01:34

As I was a Windows programmer it was so easy to show a message box on a form.

But on an ASP.NET page I don\'t know how can I show it?

Actually I have some co

相关标签:
8条回答
  • 2020-12-20 01:55

    If you REALLY want to have "yes"/"no" buttons (or any buttons that are not your standard OK/Cancel for that matter) you can do the following:

    Main page:

    <html>
    <body>
    <script>
    
    
    function ShowYesNo() {    
        var answer = window.showModalDialog("myModalDialog.htm", '', "dialogWidth:300px; dialogHeight:200px; center:yes");
    
    
           document.write('Clicked yes');
        } else {
           document.write('Clicked no');
        }
    }
    
    ShowYesNo();
    
    </script>
    
    
    </body>
    </html>
    

    MyModalDialog.htm

    <html>
    <body>
    
    <p> Do you want to proceed?" </p>
    <input type = "button" id = "buttonYes" value = "Yes" onclick = "buttonOnClick('yes')">&nbsp;
    <input type = "button" id = "buttonNo" value = "No" onclick = "buttonOnClick('no')">
    
    <script type = "text/javascript">
    function buttonOnClick(message) {
        window.returnValue = message;
        window.close();
    }
    </script> 
    
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-20 01:59

    The only way to show a Yes No dialog, is to design a custom one (Javascript confirm can only produce OK and Cancel).

    Luckily, ASP.NET Ajax controls (Ajaxcontroltoolkit) makes this job easy, as you can have a panel as your messagebox with the buttons you want, and have a ModalPopupExtender to imitate a dialog.

    EDIT:

    For what you ask with javascript, you can do it (and it is a much simpler solution than any seen so far), but prepared to only have OK and Cancel as the two possible answers. UI Designer Nightmare ! :(

    Basically, have the following two properties in your aspx page for that button or whatever:

    onClientClick = "javascript:confirm('you sure you wanna do this?');" onClick="myButton_Click"
    

    onClick will only run if OK is pressed on the msg dialog.

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