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

How can you catch parsing exceptions for filtering?

2 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean Brothers
Top achievements
Rank 1
Sean Brothers asked on 29 Jun 2010, 01:51 AM
When a value is entered into a filter that the automatic parser cannot parse, an exception is thrown, for example, if "2010" is entered into a DateTime filter box.  How can this exception be caught so that it can be dealt with instead of invalidating the page?

Example exception:

ERROR DETAILS
Message : String was not recognized as a valid DateTime.
Source : mscorlib
Stack Trace : at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at lambda_method(Closure , ExchangeRate )
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
at System.Linq.EnumerableExecutor`1.ExecuteBoxed()
at Telerik.Web.UI.GridDynamicQueryable.Count(IQueryable source)
at Telerik.Web.UI.GridDataTableFromEnumerable.FillData35()
at Telerik.Web.UI.GridDataTableFromEnumerable.FillData()
at Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized()
at Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields)
at Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields)
at Telerik.Web.UI.GridTableView.get_ResolvedDataSource()
at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
at Telerik.Web.UI.GridTableView.PerformSelect()
at Telerik.Web.UI.GridTableView.DataBind()
at Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)
at Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
TargetSite : Parse

2 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 01 Jul 2010, 01:28 PM
Hello Sean,

One way is to handle the error on the page level or application level - in the former case, just override the OnError event of the page, in the latter use the Application_Error method:

protected override void OnError(EventArgs e)
{
    base.OnError(e);
      
    //clear the exception
    Server.ClearError();
    //transfer the request back to the page
    Server.Transfer("default.aspx");
}

Another approach is just to avoid the exception by setting RadGrid's EnableLinqExpressions="false".

Hope it helps.

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sean Brothers
Top achievements
Rank 1
answered on 04 Jul 2010, 09:11 PM
Unfortunately, the Page_Error method doesn't prevent the page from being invalidated.

It seems the easiest approach is to use GridNumericColumns or GridDateTimeColumn which disallow invalid input instead of GridBoundColumn.

I will check out the EnableLinqExpressions property as well.
Tags
Grid
Asked by
Sean Brothers
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Sean Brothers
Top achievements
Rank 1
Share this question
or