locked
Error not getting displayed RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I am trying below code but error is not getting displayed if there is some error. For e.g i have written below line and it should display error on Client Side

    Request.QueryString["tmp"] != "ABC"

    try
            {
                con.ConnectionString = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
                if (Request.QueryString["tmp"] != null && Request.QueryString["tmp"].ToString() != "")
                {
                    if (!Page.IsPostBack)
                    {
                        con.Open();
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.ToString();
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<script type = 'text/javascript'>");
                sb.Append("window.onload=function(){");
                sb.Append("alert('");
                sb.Append(message);
                sb.Append("')};");
                sb.Append("</script>");
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
            }

    Thanks

    Wednesday, December 19, 2018 10:49 AM

Answers

  • User753101303 posted

    Hi,

    Use "view source" to see the generated code and F12 Console for possibler errors. Your code won't work if the message includes a ' character.

    Not directly related but usually you don't show exception messages on the client side where the user won't know what to do next and you'll never know unless it is reported. usually you show an generic message and write the error to a location the IT/dev team can check.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 19, 2018 1:13 PM