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

前端 未结 8 601
青春惊慌失措
青春惊慌失措 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:42

    i have a solution for you, may be it help you, for using that same message box or conformation dialog of c# in Asp.Net, first you should add namespace,

    Using System.Windows.Forms;

    then, where you want to call a message box or conformation dialog, you can just call it as simple as in c#, like:

    DialogResult dialogResult = MessageBox.Show("Are you shure?", "Some Title", MessageBoxButtons.YesNo);

        if (dialogResult == DialogResult.Yes)
        {
            Response.Redirect("Page.aspx");
        }
        else if (dialogResult == DialogResult.No)
        {
            MessageBox.Show("You Select Nothing to do... :(");
      }
    

    I think, I explained properly, sorry for any mistake....

    0 讨论(0)
  • 2020-12-20 01:44

    You can do this using JavaScript. Include this snippet in your code -

    <script type='text/javascript'>
        document.getElementById("someButtonId").onclick = function() {
            var confirmation = window.confirm("Are you sure?"); //confirmation variable will contain true/false.
    
            if(confirmation) { /* Write code for Yes */ }
            else { /* Write code for No */ }
        }
    </script>
    
    0 讨论(0)
  • 2020-12-20 01:48

    .aspx markup

    <head runat="server">
        <title>Sample Page</title>
        <script type="text/javascript">
          function doSubmit(){
                var confirmation = window.confirm("Are you sure?");
                document.getElementById("HiddenField1")["value"]=confirmation;
                return true;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server" onsubmit="return doSubmit()" >
        <div>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </div>
        </form>
    </body>
    

    Code-behind

    protected void Page_Load(object sender, EventArgs e)
    {
        if (HiddenField1.Value == "true")
        {
    
        }
        else
        {
    
        }
    }
    
    0 讨论(0)
  • 2020-12-20 01:49

    You can use

    window.confirm 
    

    for this.

    It displays a modal dialog with a message and two buttons, OK and Cancel.

    window.confirm

    Eg:

    if (window.confirm("Want to see my mood ring?")) 
    { 
        // wants to continue
    }
    else
    {
       // cancel the action
    }
    

    Edit:

    You can also develop custom message boxes using jQuery. Here is a nice one

    jQuery Impromptu

    0 讨论(0)
  • 2020-12-20 01:50

    window.alert(); window.confirm(); and window.prompt(); This is I guess what you are looking for.

    0 讨论(0)
  • 2020-12-20 01:53

    You can use the confirm JavaScript function, but that will be limited to OK/Cancel as options. If this is not what you want, you can lean on the VBScript MsgBox client-side function. Bear in mind that doing so will only work with Internet Explorer.

    function PerformDelete(id)
    {
      if(confirm("I am about to delete this record.  Is this ok?"))
      {
        //your code here
      }
    }
    
    0 讨论(0)
提交回复
热议问题