locked
Error popup not getting displayed RRS feed

  • Question

  • User-797751191 posted

    Hi

    When i comment line Clientscript & Uncomment response.write then message gets displayed.
    Try
    {
    }
            catch (Exception ex)
            {
                string message = "Critical Error Encountered !";
                
                ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
                //Response.Write("<script>alert('" + ex.Message.Replace("\'", " ") + "')</script>");
            }
    
    Below Script is written before the end Form tag
    <head>
    <link href="Css/cust.css" rel="stylesheet" type="text/css"/>
    <link href="Css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
    </head>
    <body>
    <form> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script type="text/javascript"> function ShowPopup(message) { $("#dialog").html(message); $("#dialog").dialog({ width: 400, height: 200, dialogClass: "no-close", title: "Success !", buttons: [ { text: "OK", click: function () { $(this).dialog("close"); } } ] }).css("font-size", "16px"); } </script>
    </form>
    </body>

    Thanks

    Thursday, June 27, 2019 9:12 AM

Answers

  • User475983607 posted

    jsshivalik

      Not working and neither showing any error in Developer tools.

    This is a support forum and the members are not clairvoyant.  What is not working?  What have you tried?  Did you update the code? Is there anyway you can provide all the relevant code so we are not guessing?

    I created a demo which works as expected.  The jQuery dialog opens when there is an exception.  Keep in mind you should not combine jQuery UI and Bootstrap.  Use one or the other.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqDialogDemo.aspx.cs" Inherits="WebFormsIdentity.JqDialogDemo" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link href="Content/bootstrap.css" rel="stylesheet" />
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <div>
                <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>
            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
            <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
            <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
            <script src="Scripts/bootstrap.js"></script>
            <script type="text/javascript">
    
                $("#dialog").dialog({
                    autoOpen: false,
                    width: 400,
                    height: 200,
                    dialogClass: "no-close",
                    title: "Success !",
                    buttons: [
                        {
                            text: "OK",
                            click: function () {
                                $(this).dialog("close");
                            }
                        }
                    ]
                }).css("font-size", "16px");
    
                function ShowPopup(message) {
                    //console.log(message);
                    $("#dialog > p").text(message);
                    $("#dialog").dialog("open");
                }
    
            </script>
    
        </form>
    
    </body>
    </html>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebFormsIdentity
    {
        public partial class JqDialogDemo : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
               
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                try
                {
                    throw new Exception("This is a test");
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Popup", $"$(function() {{ ShowPopup('{ex.Message}'); }} );", true);
                }
            }
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 27, 2019 3:51 PM

All replies

  • User475983607 posted

    Let's start with a few basic troubleshooting steps. 

    Are there any errors in the Dev Tools console?  Does the #dialog element exist in the markup?  Have you taken a look at the resulting HTML to verify the JS code is loaded in the expected order?

    Maybe try wrapping ShowPopup in the ready event.

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

    Thursday, June 27, 2019 1:36 PM
  • User-797751191 posted

    Hi

      Not working and neither showing any error in Developer tools.

    Thanks

    Thursday, June 27, 2019 3:07 PM
  • User475983607 posted

    jsshivalik

      Not working and neither showing any error in Developer tools.

    This is a support forum and the members are not clairvoyant.  What is not working?  What have you tried?  Did you update the code? Is there anyway you can provide all the relevant code so we are not guessing?

    I created a demo which works as expected.  The jQuery dialog opens when there is an exception.  Keep in mind you should not combine jQuery UI and Bootstrap.  Use one or the other.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqDialogDemo.aspx.cs" Inherits="WebFormsIdentity.JqDialogDemo" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link href="Content/bootstrap.css" rel="stylesheet" />
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <div>
                <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>
            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
            <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
            <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
            <script src="Scripts/bootstrap.js"></script>
            <script type="text/javascript">
    
                $("#dialog").dialog({
                    autoOpen: false,
                    width: 400,
                    height: 200,
                    dialogClass: "no-close",
                    title: "Success !",
                    buttons: [
                        {
                            text: "OK",
                            click: function () {
                                $(this).dialog("close");
                            }
                        }
                    ]
                }).css("font-size", "16px");
    
                function ShowPopup(message) {
                    //console.log(message);
                    $("#dialog > p").text(message);
                    $("#dialog").dialog("open");
                }
    
            </script>
    
        </form>
    
    </body>
    </html>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebFormsIdentity
    {
        public partial class JqDialogDemo : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
               
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                try
                {
                    throw new Exception("This is a test");
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Popup", $"$(function() {{ ShowPopup('{ex.Message}'); }} );", true);
                }
            }
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 27, 2019 3:51 PM
  • User753101303 posted

    Hi,

    You checked already that ShowPopup works before trying to launch this from a startup script ? Do you really have an element with the "dialog" id in your HTML markup ?

    Thursday, June 27, 2019 4:06 PM
  • User-797751191 posted

    Hi

      Resolved . I have not defined id=dialog anywhere in form

    Thanks

    Thursday, June 27, 2019 4:14 PM