Ext.NET icon indicating copy to clipboard operation
Ext.NET copied to clipboard

ASP.NET's Page_Error() handling is odd when clearing errors

Open fabriciomurta opened this issue 8 years ago • 2 comments

If Page_Error() clears the error message and tries to provide tailored server response, the response received by Ext.NET is always a blank json object {} and any Response.Write() or X.AddScript() call is ignored.

Found: 4.2.0 Ext.NET forum thread: General exception handling pop up

Test cases will follow.

fabriciomurta avatar Jan 31 '17 20:01 fabriciomurta

This is a failing test case. The returned response is always an empty json object (must open browser debug tools and watch network traffic/response after clicking the button in the example.

<%@ Page Language="C#" %>

<!DOCTYPE html>
<script runat="server">
    protected void Test_ButtonOnDirectClick(object sender, DirectEventArgs e)
    {
        throw new Exception("My Exception");
    }

    public void Page_Error(object sender, EventArgs e)
    {
        Exception exc = Server.GetLastError();
        X.Msg.Alert("Error", "Server side error: " + exc.Message);
        Server.ClearError();
    }
</script>

<html>
<head id="Head1" runat="server">
    <title>Default Exception Handling</title>
</head>
<body>
    <form id="Form1" runat="server">
        <h1>Default Button</h1>

        <ext:ResourceManager ID="ResourceManager1" runat="server" />

        <ext:Container ID="Container1"
            runat="server"
            Layout="VBoxLayout"
            Height="650">
            <Items>
                <ext:Button ID="btnSalvar"
                    runat="server"
                    Width="100"
                    Height="100"
                    Text="test"
                    Icon="Disk"
                    >
                    <DirectEvents>
                        <Click OnEvent="Test_ButtonOnDirectClick" />
                    </DirectEvents>
                </ext:Button>
            </Items>
        </ext:Container>
    </form>
</body>
</html>

fabriciomurta avatar Jan 31 '17 20:01 fabriciomurta

The following example is a pure ASP.NET which response is normally manipulated after a Server.ClearError() call:

<%@ Page Language="C#" %>

<script runat="server">
    protected void Submit_Click(object sender, EventArgs e)
    {
        // Exception handled by Page_Error
        throw new Exception("MyException");
    }
  
    private void Page_Error(object sender, EventArgs e)
    {
        // Get last error from the server
        Exception exc = Server.GetLastError();

        Response.Write("<h2>Default Page Error</h2>\n");
        Response.Write("<p>Server error: " + exc.Message + "</p>\n");

        // Clear the error from the server
        Server.ClearError();
    }
</script>

<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
  <title>Exception Handler Page</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <h2>Default Page</h2>
    <p>
      Click this button to throw an exception to be handled by Page_Error().<br />
      <asp:Button 
          ID="Submit1"
          runat="server"
          OnClick="Submit_Click"
          Text="test"
          />
    </p>
  </div>
  </form>
</body>
</html>

Of course, with Ext.NET the response is handled differently, as it expects a script to be run/interpreted, but the X.AddScript() method shouldn't be ignored/cleared either.

fabriciomurta avatar Jan 31 '17 21:01 fabriciomurta