PDA

View Full Version : [CLOSED] Page load error handling



bayoglu
Jan 31, 2013, 4:04 PM
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
});
}
}
}

Vladimir
Jan 31, 2013, 7:36 PM
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>

bayoglu
Feb 01, 2013, 1:03 AM
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.

Vladimir
Feb 01, 2013, 1:15 AM
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

bayoglu
Feb 01, 2013, 2:22 AM
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.

Vladimir
Feb 01, 2013, 2:29 AM
Can you post generated html (open the page in the browser and choose View Source) when DB exeception is occured?

bayoglu
Feb 01, 2013, 2:37 AM
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="/wEPDwUKLTIxODUyMjk4OWQYAQUeX19Db250cm9sc1JlcXVpcmV Qb3N0QmFja0tleV9fFgMFEFJlc291cmNlTWFuYWdlcjEFBlBhb mVsMQUKR3JpZFBhbmVsMds2DrjZm7vI83qaila8k86mVSowkXu mImXYcfCP1UjF" />
</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
});
}

bayoglu
Feb 01, 2013, 2:40 AM
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.GridPanel1Sto re=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>

Vladimir
Feb 01, 2013, 2:50 AM
Ok, you can email me the test project and I will investigate it

bayoglu
Feb 01, 2013, 2:57 AM
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.

Vladimir
Feb 01, 2013, 3:17 AM
I was able to reproduce the issue. It seems that IQueryable object is passed to DataSource raises an exception and somehow breaks Ext.Net rendering
Workaround: force DB reading by calling ToList before passing to Store


GridPanel1Store.DataSource = p.ToList(); // replace 'p' by ' p.ToList()'


We will investigate and fix this issue

bayoglu
Feb 05, 2013, 10:32 PM
I was able to reproduce the issue. It seems that IQueryable object is passed to DataSource raises an exception and somehow breaks Ext.Net rendering
Workaround: force DB reading by calling ToList before passing to Store


GridPanel1Store.DataSource = p.ToList(); // replace 'p' by ' p.ToList()'


We will investigate and fix this issue

OK, thank you.

Vladimir
Feb 12, 2013, 12:08 AM
Hi,

Fixed in SVN