Load Settings with missing fields

4 posts, 1 answers
  1. Alex
    Alex avatar
    31 posts
    Member since:
    Jun 2011

    Posted 30 Nov 2012 Link to this post

    I am building a filter string based on a list of dynamic fields and saving the filter using the SaveSettings() encoded string.  I need to be able to restore this as well, however, it is possible that some of the fields in the filter are no longer available.  When this is the case, LoadSettings() throws an Object reference exception at RadFilterDataFieldEditor.  I would like to be able to simply invalidate the expressions that are no longer able to be part of the filter, but the exception doesn't give me any detail to work with.

    Is there an alternate way of loading the expressions from the encoded string that would give me this detail?
  2. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 05 Dec 2012 Link to this post

    Hi Alex,

    There is no such build in functionality that to allow loading only the valid part of the settings. This save/load is based on the IStateManager's SaveViewState and we have pretty much no control over it.

    In your case you will have to implement another way of saving such settings that to allows you to load only some of them. You can loop the FilterExpression to save it in some custom collection and later to try to recreate valid FilterExpression. Check this help topic about working with the expressions:
    http://www.telerik.com/help/aspnet-ajax/filter-working-with-expressions.html

    All the best,
    Vasil
    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. Daniel
    Daniel avatar
    7 posts
    Member since:
    May 2013

    Posted 04 Dec 2013 Link to this post

    I am having the same problem with an Object reference exception at RadFilterDataFieldEditor, which is caused by some non-more-existent fields in the filter. But in my case I am not interested in restoring the other fields, I only want to take care of the exception.

    The errorneous code is:
    try
    {
    MyRadFilter.LoadSettings(myCodedString);
    }

    What I want to do is to catch the exception by loading an empty setting into the radfilter to prevent the site from crashing, like this:
    catch
    {
    MyRadFilter.LoadSettings(emptyString);
    }

    How could I do this? I have tried with inserting empty strings, inserting null, and using RadFilterExpressions, but all of them throws a new exception. If I don't do like this the page will crash so I have to figure something out.
    Any idea?
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 09 Dec 2013 Link to this post

    Hello Daniel,

    You can add the fields one by one inside try block. And this should work. However the integrated LoadSettings and SaveSettings methods can not be used if you want to load only part of the settings.

    Regards,
    Vasil
    Telerik
    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 the blog feed now.
Back to Top