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

Load Settings with missing fields

3 Answers 35 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 01 Dec 2012, 01:21 AM
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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 05 Dec 2012, 05:21 PM
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.
0
Daniel
Top achievements
Rank 1
answered on 04 Dec 2013, 03:32 PM
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?
0
Vasil
Telerik team
answered on 09 Dec 2013, 03:41 PM
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.
Tags
Filter
Asked by
Alex
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or