JavaScript does not work in Request Failure window

  1. #1

    JavaScript does not work in Request Failure window

    Hi all,
    In my web application, I want to handle Ext.Net Ajax exceptions that occurs when request to server and show friendly error message.
    I wrote some JavaScript codes in my error message HTML to do some actions in the code bellow.
    When clicking on the Detail link on the shown error message window to get more details of the error message, but the JavaScript does not act anything.
    Do you know what's reason here and could you please give me an advice?

    Thanks so much.



     Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            Dim curError As System.Exception = HttpContext.Current.Error
            Response.Clear()
            Response.ClearHeaders()
            Response.StatusCode = 500
            Response.Write(GetErrorMessage(curError))
            Response.End()
        End Sub
    
        Private Function GetErrorMessage(ByVal e As Exception) As String
            Dim strHTML As New StringBuilder()
            strHTML.AppendLine("<html>")
            strHTML.AppendLine("<head>")
            strHTML.AppendLine("<title>")
            strHTML.AppendLine("</title>")
            strHTML.AppendLine("<script type='text/javascript'>")
            strHTML.AppendLine("function viewDetail(){")
            strHTML.AppendLine("var pnlDetail = document.getElementById('pnlDetail');")
            strHTML.AppendLine("if (pnlDetail.style.visibility == 'visible') {")
            strHTML.AppendLine("   pnlDetail.style.visibility = 'hidden';")
            strHTML.AppendLine(" else {")
            strHTML.AppendLine("  pnlDetail.style.visibility = 'visible';")
            strHTML.AppendLine("}}")
            strHTML.AppendLine("</script>")
            strHTML.AppendLine("</head>")
            strHTML.AppendLine("<body>")
            strHTML.AppendLine("<b>An error occured! </b>")
            strHTML.AppendLine("<br>")
            strHTML.AppendLine("<a onclick='viewDetail();'>Detail</a>")
            strHTML.AppendLine("<div id='pnlDetail' style='visibility:hidden'>")
            strHTML.AppendLine("Error Message Detail")
            strHTML.AppendLine("</div>")
            strHTML.AppendLine("</body>")
            strHTML.AppendLine("</html>")
            Return strHTML.ToString()
        End Function
    Last edited by sonnh11; Feb 10, 2012 at 6:29 AM.
  2. #2
    Hi,

    Please don't deal with Response directly during DirectEvent. Only in the case of downloading a file.

    We use Response internally in DirectEvent.

    Please investigate:
    http://forums.ext.net/showthread.php?17247
  3. #3

    JavaScript does not work in Request Failure window

    Hi Daniil,
    I did mean the JavaScript codes in the GetErrorMessage function does not work. Do you know what's the reason here or could you please explain more details for your last post?

    Thanks for quickly response and helps!
    Last edited by sonnh11; Feb 13, 2012 at 2:19 AM. Reason: Add more question
  4. #4
    Got it.

    The body of RequestFailure window is an HtmlEditor in design mode. It can't execute JavaScript.

    Please return a JSON object from Application_Error and handle it withing DirectEvent's Failure or ResourceManager's AjaxRequestException.

    Example Page
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void TestDirectEventHandler1(object sender, DirectEventArgs e)
        {
            throw new Exception("I'm the Exception of DirectEvent 1");
        }
    
        protected void TestDirectEventHandler2(object sender, DirectEventArgs e)
        {
            throw new Exception("I'm the Exception of DirectEvent 2");
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            var onAjaxRequestException = function (response, result, el, eventType, action, extraParams, o) {
                var r = Ext.decode(response.responseText);
                
                Window1.show();
                DisplayFieldStatus.setValue(response.status);
                DisplayFieldStatusText.setValue(response.statusText);
                DisplayFieldMsg.setValue(r.msg);
                DisplayFieldDetails.setValue(r.details);
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" ShowWarningOnAjaxFailure="false">
                <Listeners>
                    <AjaxRequestException Fn="onAjaxRequestException" />
                </Listeners>
            </ext:ResourceManager>
            <ext:Button runat="server" Text="Test 1" OnDirectClick="TestDirectEventHandler1" />
            <ext:Button runat="server" Text="Test 2" OnDirectClick="TestDirectEventHandler2" />
            <ext:Window 
                ID="Window1" 
                runat="server" 
                Title="Failure" 
                Hidden="true"
                Layout="FormLayout"
                Icon="Error"
                Width="400"
                Height="300">
                <Items>
                    <ext:DisplayField ID="DisplayFieldStatus" runat="server" FieldLabel="Status" />
                    <ext:DisplayField ID="DisplayFieldStatusText" runat="server" FieldLabel="Status text" />
                    <ext:DisplayField ID="DisplayFieldMsg" runat="server" FieldLabel="Message" />
                    <ext:DisplayField ID="DisplayFieldDetails" runat="server" FieldLabel="Details" />
                </Items>    
            </ext:Window>
        </form>
    </body>
    </html>
    Example Application_Error
    protected void Application_Error(object sender, EventArgs e)
    {
        Exception exception = HttpContext.Current.Error;
        Response.Clear();
        Response.StatusCode = 500;
        Response.ContentType = "application/json";
        Response.Write(JSON.Serialize(new 
        { 
            msg = exception.InnerException.Message,
            details = "Some details"
        }));
        Response.End();
    }
  5. #5
    Thank you very much!

Similar Threads

  1. Replies: 2
    Last Post: Feb 02, 2012, 5:30 AM
  2. Hide Request Failure default popup window
    By brittongr in forum 1.x Help
    Replies: 2
    Last Post: Jan 06, 2012, 11:37 AM
  3. Replies: 16
    Last Post: Oct 04, 2011, 5:17 PM
  4. [CLOSED] [1.0] Request Failure Window
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 15, 2010, 8:33 AM
  5. Replies: 2
    Last Post: Nov 26, 2008, 12:17 PM

Tags for this Thread

Posting Permissions