RadFilter and Related RadListBoxes

8 posts, 1 answers
  1. Tom Rasmussen
    Tom  Rasmussen avatar
    20 posts
    Member since:
    Jan 2009

    Posted 06 Feb 2013 Link to this post

    I'm not sure if this belongs here, under RadListBox or under Ajax (perhaps all three).  But here it goes.

    I came across an interesting error when using two RadListBoxes and RadFilter on the same page when the RadFilter was placed inside of a RadAjaxPanel.  I managed to strip down the code to the very basics and still be able to reliably reproduce the error.

    ASPX:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListBoxErrorTesting2.aspx.cs" Inherits="Testing.ListBoxErrorTesting2" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
             
            <telerik:RadListBox ID="SourceListBox" runat="server" AllowTransfer="true" TransferMode="Move" TransferToID="DestinationListBox" />
            <telerik:RadListBox ID="DestinationListBox" runat="server" />
         
            <br />
         
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
            <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1">
                <telerik:RadFilter runat="server" ID="ReportFilter">
                    <FieldEditors>
                        <telerik:RadFilterTextFieldEditor FieldName="Title" DisplayName="Title" />
                    </FieldEditors>
                </telerik:RadFilter>
            </telerik:RadAjaxPanel>
     
        </div>
        </form>
    </body>
    </html>

    And the code behind:
    using System;
     
    namespace Testing
    {
        public partial class ListBoxErrorTesting2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack) return;
     
                var data = new[] { "Item1", "Item2", "Item3", "Item4", "Item5" };
                DestinationListBox.DataSource = data;
                DestinationListBox.DataBind();
            }
        }
    }

    As you can see, this is a very basic setup.  One of the list boxes is data bound from a simple array of strings.  The filter has nothing but a single static editor.  The filter is wrapped in an update panel since we do not want or need to update the list boxes if a filter expression or group is added/modified/removed.  Yet, if the list boxes are interacted with, the filter will eventually throw the following exception:  Index was out of range.
    System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
       at System.Collections.ArrayList.get_Item(Int32 index)
       at System.Web.UI.StateManagedCollection.System.Collections.IList.get_Item(Int32 index)
       at Telerik.Web.UI.ControlItemCollection.get_Item(Int32 index) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\Common\Navigation\ControlItemCollection.cs:line 30
       at Telerik.Web.UI.ClientStateLogPlayer`1.Remove(ControlItemCollection items, Int32 index) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\Common\Navigation\ClientStateLogPlayer.cs:line 142
       at Telerik.Web.UI.ClientStateLogPlayer`1.Play(ClientStateLogEntry entry) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\Common\Navigation\ClientStateLogPlayer.cs:line 62
       at Telerik.Web.UI.ClientStateLogPlayer`1.Play(IEnumerable`1 clientStateLogEntry) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\Common\Navigation\ClientStateLogPlayer.cs:line 27
       at Telerik.Web.UI.RadListBox.LoadLogEntries(RadListBoxClientState clientState) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\ListBox\RadListBox.cs:line 906
       at Telerik.Web.UI.RadListBox.LoadClientState(RadListBoxClientState clientState) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\ListBox\RadListBox.cs:line 892
       at Telerik.Web.UI.RadListBox.LoadPostData(String postDataKey, NameValueCollection postCollection) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\ListBox\RadListBox.cs:line 800
       at Telerik.Web.UI.RadDataBoundControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) in D:\Dev\clientaccessweb\Caw.ClientAccessWeb\trunk\Shared\TelerikSource\Telerik.Web.UI\Common\RadDataBoundControl.cs:line 653
       at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.main_testing_listboxerrortesting2_aspx.ProcessRequest(HttpContext context) in c:\Users\trasmussen\AppData\Local\Temp\Temporary ASP.NET Files\root\e99f54ff\b41660f1\App_Web_listboxerrortesting2.aspx.dc92d279.2k6ikk-w.0.cs:line 0
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    The number of times you can make Ajax callbacks with the filter depends on how you have interacted with the list boxes.  The quickest way was to move all items to the left, then one item back to the right.  The second click of Add Expression throws the error.

    This may not be limited to just RadFilter, but any control within a RadAjax panel.  I did not get that far in my testing.

    I can bypass the issue by wrapping all the controls in the ajax panel or using an ajax manager, but that's not really the point.
  2. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 11 Feb 2013 Link to this post

    Hi Tom,

    After examining the code I may have found the problem. It occurs because the client state of the RadListBoxes is not properly updated. In order to resolve this you have to set the AutoPostBackOnTransfer
    property of the SourceListBox to true. For more information on this subject please review this forum post in which the same problem is being discussed.

    Regards,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tom Rasmussen
    Tom  Rasmussen avatar
    20 posts
    Member since:
    Jan 2009

    Posted 11 Feb 2013 Link to this post

    This is just another way of doing a postback on the related rad list boxes.  As I mentioned, I can accomplish this by ajaxifying the listboxes, in a panel or manager, but I was looking for information on how to handle this without having to postback.
  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 14 Feb 2013 Link to this post

    Hello Tom,

    I am sorry to say but without setting the AutoPostBackOnTransfer to true the ViewState of both RadListBoxes will not update correctly. In other words you need to postback. In order to not reload the page I suggest that you use AJAX.

    Kind regards,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Tom Rasmussen
    Tom  Rasmussen avatar
    20 posts
    Member since:
    Jan 2009

    Posted 15 Feb 2013 Link to this post

    Thanks Angel.

    At least I know I'm not doing something stupid here.  I decided to use an ajax manager and update the list boxes using the filter as a trigger.  It works perfect.
  7. Emily
    Emily avatar
    6 posts
    Member since:
    Mar 2013

    Posted 05 Mar 2013 Link to this post

    Hi, I had the same problem. However, I set AutoPostBackOnTransfer to false because when it was set to true, it was reloading the page everytime which sent the user to the top of the page. We obviously want the page not to move when clicking one of the transfer buttons. Is there another way to prevent this from happening? We have a submit button that allows the code to submit to the server without the AutoPostBackOnTransfer being set to true. The error is thrown when it sits too long before the submit button is clicked. Thanks!
  8. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 06 Mar 2013 Link to this post

    Hi Emily,

    As I have previously explained setting AutoPostBackOnTransfer to false will cause an error as the ViewState of the ListBoxes will not update correctly. Since your requirements is to save the scroll position I suggest that you examine this online resource which should help you to resolve the problem.

    Kind regards,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Emily
    Emily avatar
    6 posts
    Member since:
    Mar 2013

    Posted 07 Mar 2013 Link to this post

    Hi Angel,

    Thank you so much for your response. That page helped a lot. It was a great simple fix and I really appreciate your answer!

    Thanks again,
    Emily
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017