c#中的弹出消息框

San*_*ior 0 asp.net messagebox webusercontrol

我正在寻找类似于http://www.how-to-asp.net/messagebox-control-aspnet/的自定义用户控件,但能够显示为弹出窗口.消息框应该具有从asp.net 4中的代码调用的功能,使用事件挂钩来绑定"ok"和"cancel"按钮.

我熟悉Ajax Toolkit和JQuery.

类似方向的参考和/或样本将非常有用.

谢谢!

Hum*_*mpy 5

使用jQuery UI.他们有很好的例子.我一直在使用对话框.

您可以查看它们的来源,这是一个例子.

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>

<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>


</body>
Run Code Online (Sandbox Code Playgroud)

无论如何,您都可以自定义此项.该链接将告诉您如何执行此操作.

编辑:因为你想在后面的代码中打开它,我将向你展示我的jQuery以及我如何在后面的代码中调用它.我用它来发送电子邮件.

function sendEmail() {
    $("#email").dialog({
       modal: true,
       width: 700,
       buttons: {
          "Send": function () {
             var btn = document.getElementById("<%=lbSend.ClientID %>");
             if (btn) btn.click();
             $(this).dialog("close");
           },
           Cancel: function () {
              $(this).dialog("close");
            }
        }
      );
      jQuery("#email").parent().appendTo(jQuery("form:first"));
    };
Run Code Online (Sandbox Code Playgroud)

然后在后面的代码中.

 protected void btnEmail_Click(object sender, EventArgs e)
 {
      //this calls the jQuery function.
      Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "sendEmail();", true);
 } 
Run Code Online (Sandbox Code Playgroud)