This is a migrated thread and some comments may be shown as answers.

AJAX Error Handling with LINQDataSource

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rpritchard77
Top achievements
Rank 1
rpritchard77 asked on 20 Jan 2009, 11:39 PM
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.

 

 

        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">  
                        <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);  
        }         
    } 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 26 Jan 2009, 07:54 AM
Hello,

To further investigate the setup, since I am not aware of the datasource declaration, as well as the complete setup, you can open a formal support ticket, and attach a small project sample, for further investigation. I will review it locally, and get back to you with additional information.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
rpritchard77
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or