I cannot seem to find a way to handle errors in certain situations. I have added the following property to a partial class that extends one of the LINQ to SQL objects in my project by decrypting a SSN field for output. This will generate an error if the key does not match the original key.
Only one record of my list of employees generates an error and this employee shows up on page 5 of my grid. When I click the page 5 navigation, the RadAjaxLoadingPanel shows, hides, and the status bar reads "Loading..." without the contents of the grid actually updating. I get similar behavior in other situations when there is a binding error during an AJAX call. I'd like to know how to handle this error, or the best way to work around this behavior.
Here is the relevant code:
Code Behind
public string SSN |
{ |
get |
{ |
if (string.IsNullOrEmpty(ssn)) |
ssn = EncryptedSSN.DESDecrypt("KEYKEYKE"); |
return ssn; |
} |
set { ssn = value; } |
} |
Only one record of my list of employees generates an error and this employee shows up on page 5 of my grid. When I click the page 5 navigation, the RadAjaxLoadingPanel shows, hides, and the status bar reads "Loading..." without the contents of the grid actually updating. I get similar behavior in other situations when there is a binding error during an AJAX call. I'd like to know how to handle this error, or the best way to work around this behavior.
Here is the relevant code:
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" /> |
<telerik:RadScriptManager runat="server" /> |
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="itemsGrid"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="itemsGrid" LoadingPanelID="RadAjaxLoadingPanel1" /> |
<telerik:AjaxUpdatedControl ControlID="messageCenter" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="reloadButton"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="itemsGrid" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="200px" Width="200px" Transparency="15" BackColor="LightGray"> |
<img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /> |
</telerik:RadAjaxLoadingPanel> |
<div> |
<thin:MessageCenter ID="messageCenter" runat="server" /> |
</div> |
<div id="listTableContainer"> |
<telerik:RadGrid ID="itemsGrid" runat="server" AllowAutomaticDeletes="True" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" DataSourceID="employees" GridLines="None" PageSize="50" Skin="Vista" AllowMultiRowSelection="True" ShowStatusBar="True" OnItemDeleted="itemsGrid_ItemDeleted"> |
<HeaderContextMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</HeaderContextMenu> |
<AlternatingItemStyle BackColor="#F6F7F9" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="False" /> |
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="False" /> |
<SelectedItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="False" /> |
<PagerStyle Mode="NextPrevNumericAndAdvanced" /> |
<MasterTableView AutoGenerateColumns="False" DataSourceID="employees" DataKeyNames="ID" ClientDataKeyNames="ID" CommandItemDisplay="Top"> |
<CommandItemTemplate> |
<div id="toolbarContainer" class="Toolbar"> |
<a href="javascript:OpenItemWindow('Employee',0,0);"> |
<asp:Image ID="Image1" runat="server" SkinID="AddButton" AlternateText="Add New" /> |
<span>Add New</span> </a> |
<asp:LinkButton ID="deleteLink" runat="server" OnClientClick="javascript:return confirm('Delete all selected items?')" CommandName="DeleteSelected"> |
<asp:Image ID="Image2" runat="server" SkinID="DeleteButton" AlternateText="Delete" /> |
<span>Delete Selected</span> |
</asp:LinkButton> |
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="RebindGrid"> |
<asp:Image ID="Image3" runat="server" SkinID="RefreshButton" /> |
<span>Refresh</span> |
</asp:LinkButton> |
</div> |
</CommandItemTemplate> |
<Columns> |
<telerik:GridButtonColumn CommandName="Delete" ConfirmText="Are you sure you want to delete this item? This action cannot be undone." ConfirmTitle="Are you sure?" Text="Delete" UniqueName="column"> |
<HeaderStyle Width="50px" /> |
</telerik:GridButtonColumn> |
<telerik:GridBoundColumn DataField="SSN" HeaderText="SSN" ReadOnly="True" SortExpression="SSN" UniqueName="SSN"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" ReadOnly="True" SortExpression="FirstName" UniqueName="FirstName"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="MiddleName" HeaderText="Middle Name" ReadOnly="True" SortExpression="MiddleName" UniqueName="MiddleName"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" ReadOnly="True" SortExpression="LastName" UniqueName="LastName"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Suffix" HeaderText="Suffix" ReadOnly="True" SortExpression="Suffix" UniqueName="Suffix"> |
</telerik:GridBoundColumn> |
<telerik:GridCheckBoxColumn DataField="Active" DataType="System.Boolean" HeaderText="Active" ReadOnly="True" SortExpression="Active" UniqueName="Active"> |
</telerik:GridCheckBoxColumn> |
</Columns> |
</MasterTableView> |
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"> |
<Selecting AllowRowSelect="True" /> |
<Scrolling AllowScroll="True" UseStaticHeaders="True" /> |
<Resizing AllowColumnResize="true" ResizeGridOnColumnResize="false" /> |
<ClientEvents OnGridCreated="GridCreated" OnRowDblClick="RowDblClick" /> |
</ClientSettings> |
<FilterMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</FilterMenu> |
</telerik:RadGrid> |
<asp:LinqDataSource ID="employees" runat="server" |
ContextTypeName="DBDataContext" |
OrderBy="Active, LastName, FirstName" |
TableName="Employees" |
EnableDelete="True" OnSelected="employees_Selected" /> |
Code Behind
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
Page.DataBind(); |
} |
public void reloadButton_Click(object sender, EventArgs e) |
{ |
itemsGrid.Rebind(); |
} |
protected void itemsGrid_ItemDeleted(object source, GridDeletedEventArgs e) |
{ |
GridDataItem dataItem = (GridDataItem)e.Item; |
String id = dataItem.GetDataKeyValue("ID").ToString(); |
if (e.Exception != null) |
{ |
e.ExceptionHandled = true; |
messageCenter.DisplayMessage("Employee could not be deleted. " + e.Exception.Message, Resources_Controls_MessageCenter.MessageType.Error); |
} |
else |
{ |
messageCenter.DisplayMessage("Employee(s) deleted.", Resources_Controls_MessageCenter.MessageType.Success); |
} |
} |
public void employees_Selected(object sender, LinqDataSourceStatusEventArgs e) |
{ |
if (e.Exception != null) |
{ |
e.ExceptionHandled = true; |
messageCenter.DisplayMessage("Employees list could not be obtained. " + e.Exception.Message, Resources_Controls_MessageCenter.MessageType.Error); |
} |
} |