locked
Dialog Box not appearing RRS feed

  • Question

  • User-1499457942 posted

    Hi

     I have below code but message is not appearing

    protected void btnupload_Click(object sender, EventArgs e)
    {

    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);

    }

    <script type="text/javascript">
            function ShowPopup(message) {
                $(function () {
                    $("#dialog").html(message);
                    $("#dialog").dialog({
                        title: "Success",
                        buttons: {
                            Close: function () {
                                $(this).dialog('close');
                            }
                        },
                        modal: true
                    });
                });
            };
    </script>
    
    <form id="form1" runat="server">
            <div id="dialog" style="display: none">
            </div>
    </form>

    Thanks

    Monday, June 25, 2018 4:50 AM

Answers

  • User-369506445 posted

    hi

    I fixed it for you, please try below code :

    <!DOCTYPE html>
    <html runat="server" xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <script>
            function ShowPopup(message) {
                $("#dialog").html(message);
                $("#dialog").dialog({
                    dialogClass: "no-close",
                    buttons: [
                        {
                            text: "OK",
                            click: function () {
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
            }
        </script>
    
    </head>
    <body runat="server">
        <form id="form1" runat="server">
            <div id="dialog" style="display: none"></div>
            <asp:Button ID="btnupload" runat="server" Text="Button" OnClick="btnupload_OnClick" />
        </form>
    </body>
    </html>

    Code behind

     protected void btnupload_OnClick(object sender, EventArgs e)
            {
                var message = "vahid bakhtiary";
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
            }
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 25, 2018 5:30 AM

All replies

  • User-369506445 posted

    hi

    I fixed it for you, please try below code :

    <!DOCTYPE html>
    <html runat="server" xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <script>
            function ShowPopup(message) {
                $("#dialog").html(message);
                $("#dialog").dialog({
                    dialogClass: "no-close",
                    buttons: [
                        {
                            text: "OK",
                            click: function () {
                                $(this).dialog("close");
                            }
                        }
                    ]
                });
            }
        </script>
    
    </head>
    <body runat="server">
        <form id="form1" runat="server">
            <div id="dialog" style="display: none"></div>
            <asp:Button ID="btnupload" runat="server" Text="Button" OnClick="btnupload_OnClick" />
        </form>
    </body>
    </html>

    Code behind

     protected void btnupload_OnClick(object sender, EventArgs e)
            {
                var message = "vahid bakhtiary";
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
            }
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 25, 2018 5:30 AM
  • User-1499457942 posted

    Hi Vahid

     Popup still not appearing

    Thanks

    Monday, June 25, 2018 5:56 AM
  • User-369506445 posted

    are you sure? I tried this ample and it worked well,

    please create a new project and just try this sample, then tell me your feedback

    or put your complete code here

    Monday, June 25, 2018 6:00 AM
  • User-1499457942 posted

    Hi Vahid

      Working . What was the difference

    Thanks

    Monday, June 25, 2018 6:07 AM
  • User-369506445 posted

    you should add the jquery reference for a dialog box

    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>


     

    Monday, June 25, 2018 6:30 AM