[CLOSED] Page load error handling

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Page load error handling

    Hello,

    The question is about handling page load errors and notifying user via Ext.Msg. The problem follows: When the DB is not accessible, page renders empty (as expected) but X.Msg is not shown. What is the correct way of handling those exceptions?

    Thank you.

    aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>"Combobox editor"</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server"/>
            <ext:Store ID="GridPanel1Store" runat="server">
                <Model>
                    <ext:Model ID="GridPanel1Model" runat="server" IDProperty="ID">
                        <Fields>
                            <ext:ModelField Name="ID" Type="Int"></ext:ModelField>
                            <ext:ModelField Name="Name" Type="String"></ext:ModelField>
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        <div>
            <ext:Viewport ID="Viewport1" runat="server" Layout="FitLayout">
                <Items>
                    <ext:Panel ID="Panel1" runat="server" Layout="FitLayout" AutoScroll="true">
                        <Items>
                            <ext:GridPanel ID="GridPanel1" runat="server" StoreID="GridPanel1Store" MinHeight="200">
                                <ColumnModel runat="server" ID="ColumnModel1">
                                    <Columns>
                                        <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" Align="Left" Flex="1">
                                        </ext:Column>
                                        <ext:Column ID="Column2" runat="server" Text="Name" DataIndex="Name" Align="Left" Flex="1">
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>  
                            </ext:GridPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>    
        </div>
        </form>
    </body>
    </html>

    aspx.cs:

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    testEntities context = new testEntities();
                    try
                    {
                        var p = (from v in context.testTables select new { ID = v.ID, Name = v.Name });
                        GridPanel1Store.DataSource = p;
                        GridPanel1Store.DataBind();
                    }
                    catch (Exception exc)
                    {
                        Server.ClearError();
                        X.Msg.Show(new MessageBoxConfig
                        {
                            Title = "Error loading...",
                            Message = exc.Message,
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR
                        });
                    }
                }
            }
    Last edited by Daniil; Feb 12, 2013 at 9:22 AM. Reason: [CLOSED]
  2. #2
    I see the error message if run your sample
    <%@ Page Language="C#" %>
     <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
     
    <!DOCTYPE html>
     
    <html>
    <head id="Head1" runat="server">
        <title>"Combobox editor"</title>
    
    
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    Server.ClearError();
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error loading...",
                        Message = "Error",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR
                    });
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server"/>
            <ext:Store ID="GridPanel1Store" runat="server">
                <Model>
                    <ext:Model ID="GridPanel1Model" runat="server" IDProperty="ID">
                        <Fields>
                            <ext:ModelField Name="ID" Type="Int"></ext:ModelField>
                            <ext:ModelField Name="Name" Type="String"></ext:ModelField>
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        <div>
            <ext:Viewport ID="Viewport1" runat="server" Layout="FitLayout">
                <Items>
                    <ext:Panel ID="Panel1" runat="server" Layout="FitLayout" AutoScroll="true">
                        <Items>
                            <ext:GridPanel ID="GridPanel1" runat="server" StoreID="GridPanel1Store" MinHeight="200">
                                <ColumnModel runat="server" ID="ColumnModel1">
                                    <Columns>
                                        <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" Align="Left" Flex="1">
                                        </ext:Column>
                                        <ext:Column ID="Column2" runat="server" Text="Name" DataIndex="Name" Align="Left" Flex="1">
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>  
                            </ext:GridPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>    
        </div>
        </form>
    </body>
    </html>
  3. #3
    Quote Originally Posted by Vladimir View Post
    I see the error message if run your sample
    <%@ Page Language="C#" %>
     <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
     
    <!DOCTYPE html>
     
    <html>
    <head id="Head1" runat="server">
        <title>"Combobox editor"</title>
    
    
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    Server.ClearError();
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = "Error loading...",
                        Message = "Error",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.ERROR
                    });
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server"/>
            <ext:Store ID="GridPanel1Store" runat="server">
                <Model>
                    <ext:Model ID="GridPanel1Model" runat="server" IDProperty="ID">
                        <Fields>
                            <ext:ModelField Name="ID" Type="Int"></ext:ModelField>
                            <ext:ModelField Name="Name" Type="String"></ext:ModelField>
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        <div>
            <ext:Viewport ID="Viewport1" runat="server" Layout="FitLayout">
                <Items>
                    <ext:Panel ID="Panel1" runat="server" Layout="FitLayout" AutoScroll="true">
                        <Items>
                            <ext:GridPanel ID="GridPanel1" runat="server" StoreID="GridPanel1Store" MinHeight="200">
                                <ColumnModel runat="server" ID="ColumnModel1">
                                    <Columns>
                                        <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" Align="Left" Flex="1">
                                        </ext:Column>
                                        <ext:Column ID="Column2" runat="server" Text="Name" DataIndex="Name" Align="Left" Flex="1">
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>  
                            </ext:GridPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>    
        </div>
        </form>
    </body>
    </html>
    Hello Vladimir,

    I also see the error message if I run your sample. The problem is that the code you submitted is not my sample. The code you sent is not hitting any entity connection error and ordinarily renders Msg in response as expected. Please see Page_Load function in my sample. I can e-mail you a complete solution if you need, or you can try setting a basic entity framework bind at page load.

    Thank you.
  4. #4
    I don't see difference with your example. In your case, try/catch block will intercept all exceptions. We can use the following code to emulate an error
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    try
                    {
                        throw new Exception("Error");
                    }
                    catch(Exception ex)
                    {
                        Server.ClearError();
                        X.Msg.Show(new MessageBoxConfig
                        {
                            Title = "Error loading...",
                            Message = ex.Message,
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR
                        });
                    }
                }
            }
    The code you sent is not hitting any entity connection error and ordinarily renders Msg in response as expected.
    Entity connection error will be intercepted in catch block and message should be shown. I don't see any fundamental differences with your sample and my
  5. #5
    Quote Originally Posted by Vladimir View Post
    I don't see difference with your example. In your case, try/catch block will intercept all exceptions. We can use the following code to emulate an error
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    try
                    {
                        throw new Exception("Error");
                    }
                    catch(Exception ex)
                    {
                        Server.ClearError();
                        X.Msg.Show(new MessageBoxConfig
                        {
                            Title = "Error loading...",
                            Message = ex.Message,
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR
                        });
                    }
                }
            }

    Entity connection error will be intercepted in catch block and message should be shown. I don't see any fundamental differences with your sample and my
    Vladimir be sure I would not insist if there was no difference. I repeat: Yes I see the error message if I change the Page_Load function as you tried (your both posts). The sad thing is that the error message is not shown when Page_Load is like in my original post. Let me know if it is very time consuming for you to test my code as it is. You can first create an entity set than make DB inaccessible and test the situation. I already have a test solution to share with you but file type is not allowed to be attached in here. Drop me an e-mail at bayoglu (at) gmail.com and I will reply with the complete test solution for you to try and see.
  6. #6
    Can you post generated html (open the page in the browser and choose View Source) when DB exeception is occured?
  7. #7
    Quote Originally Posted by Vladimir View Post
    Can you post generated html (open the page in the browser and choose View Source) when DB exeception is occured?
    The exception is caught by catch. Resulting page html is:

    <!DOCTYPE html>
    
    <html>
    <head id="Head1"><title>
    	"Page load error handling"
    </title></head>
    <body>
        <form method="post" action="WebForm1.aspx" id="form1">
    <div class="aspNetHidden">
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTIxODUyMjk4OWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgMFEFJlc291cmNlTWFuYWdlcjEFBlBhbmVsMQUKR3JpZFBhbmVsMds2DrjZm7vI83qaila8k86mVSowkXumImXYcfCP1UjF" />
    </div>
    
    <script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
    Below code is running in catch block and the resulting html is as you see above.

                    catch (Exception exc)
                    {
                        Server.ClearError();
                        X.Msg.Show(new MessageBoxConfig
                        {
                            Title = "Error loading...",
                            Message = exc.Message,
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR
                        });
                    }
  8. #8
    Quote Originally Posted by Vladimir View Post
    Can you post generated html (open the page in the browser and choose View Source) when DB exeception is occured?
    If I change the Page_Load as you posted:

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    try
                    {
                        throw new Exception("Error");
                    }
                    catch(Exception ex)
                    {
                        Server.ClearError();
                        X.Msg.Show(new MessageBoxConfig
                        {
                            Title = "Error loading...",
                            Message = ex.Message,
                            Buttons = MessageBox.Button.OK,
                            Icon = MessageBox.Icon.ERROR
                        });
                    }
                }
            }
    Msg is shown and the resulting html is as below:

    <!DOCTYPE html>
    
    <html>
    <head id="Head1">
        <link type="text/css" rel="stylesheet" href="/extjs/resources/css/ext-all-gray-embedded-css/ext.axd?v=18167" id="ext-theme" />
        <link type="text/css" rel="stylesheet" href="/extnet/resources/css/extnet-all-embedded-css/ext.axd?v=18167" />
        <script type="text/javascript" src="/extjs/ext-all-js/ext.axd?v=18167"></script>
        <script type="text/javascript" src="/extnet/extnet-all-js/ext.axd?v=18167"></script>
        <script type="text/javascript" src="/extnet/locale/ext-lang-tr-js/ext.axd?v=18167"></script>
    
        <title>"Page load error handling"</title>
        
        <script type="text/javascript">
        //<![CDATA[
            Ext.net.ResourceMgr.init({id:"ResourceManager1",aspForm:"form1",theme:"gray"});Ext.onReady(function(){window.App.GridPanel1Store=Ext.create("Ext.data.Store",{model:Ext.define("App.GridPanel1Model", {extend: "Ext.data.Model", fields:[{name:"ID",type:"int"},{name:"Name",type:"string"}],idProperty:"ID" }),storeId:"GridPanel1Store",autoLoad:true,proxy:{type:'memory'}});Ext.create("Ext.net.Viewport",{id:"Viewport1",renderTo:Ext.get("form1"),items:[{id:"Panel1",autoScroll:true,items:[{id:"GridPanel1",minHeight:200,xtype:"grid",columns:{id:"ColumnModel1",items:[{id:"Column1",flex:1,dataIndex:"ID",text:"ID"},{id:"Column2",flex:1,dataIndex:"Name",text:"Name"}]},store:"GridPanel1Store"}],layout:"fit"}],layout:"fit"});Ext.Msg.show({title:"Error loading...",buttons:Ext.Msg.OK,icon:Ext.Msg.ERROR,msg:"Error"});});
        //]]>
        </script>
    </head>
    <body>
        <form method="post" action="WebForm1.aspx" id="form1">
    <div class="aspNetHidden">
    
    
    
    </div>
    
    
    
    
        
            
        <div>
                
        </div>
        </form>
    </body>
    </html>
  9. #9
    Ok, you can email me the test project and I will investigate it
    Last edited by Vladimir; Feb 01, 2013 at 2:04 AM.
  10. #10
    Quote Originally Posted by Vladimir View Post
    Ok, you can email me the test project and I will investigate it
    vladimir at ext.net
    Thank you Vladimir. I sent the e-mail a couple of seconds ago. Please let me know if problems exist with the attachment.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: Jun 27, 2012, 2:19 PM
  2. [CLOSED] on Page load control error
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 25, 2012, 8:53 AM
  3. Global Error Handling
    By wdk in forum 1.x Help
    Replies: 2
    Last Post: Apr 03, 2012, 2:34 AM
  4. Replies: 5
    Last Post: Aug 04, 2009, 10:49 AM
  5. [CLOSED] Page Load date field error
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 19, 2009, 9:41 AM

Posting Permissions