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

RadFilter not able to use double quote

5 Answers 180 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 22 Jun 2011, 01:43 AM
Hi,

I have a RadFilter on a page which has a RadGrid with data in it.  The data in the grid may or may not contain a " in it.
If you currently attempt to use the filter with "Contains" and " in the text box, the following javascript error is thrown:

Sys.WebForms.PageRequestManagerServerErrorException: Unterminated string literal

It is a requirement that I be able to use the filter to find data that has a " in it.

My version of Telerik dlls is: 2011.1.413.35 (Q1 2011) ASP.NET AJAX

In an attempt to solve this, I have tried to do a replace before the OnApplyExpressions event finishes with Replace("\"", "\\\"") however this yields the same error as above.  The thought behind this was that I could escape it so that the javascript would no longer end prematurely.

Any help would be appreciated.
Thanks

5 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 24 Jun 2011, 08:49 AM
Hi Brett,

You need to escape double quotes in RadFilter's text fields. The exception you are getting indicates an error in the dynamic LINQ parser used to parse your filter expression. As string values in the filter expression are already escape, you need to additionally escape double quotes. You can use RadFilter's ApplyExpressions event to loop through all the parts of your expression and escape double where needed. Here is a sample implementation:

protected void RadFilter1_ApplyExpressions(object sender, RadFilterApplyExpressionsEventArgs e)
{
    HandleQuotes(e.ExpressionRoot);
}
 
protected void HandleQuotes(RadFilterGroupExpression expression)
{
    var expressions = expression.Expressions;
    foreach (var expr in expressions)
    {
        if (expr is RadFilterSingleValueExpression<string>)
        {
            var stringExpr = (RadFilterSingleValueExpression<string>)expr;
            stringExpr.Value = stringExpr.Value.Replace("\"", "\"\"");
        }
 
        if (expr is RadFilterGroupExpression)
        {
            HandleQuotes((RadFilterGroupExpression)expr);
        }
    }
}

The above HandleQuotes() method will replace your double quotes in string values into a pair of double quotes.

Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Brett
Top achievements
Rank 1
answered on 24 Jun 2011, 10:45 PM
Thank you for the reply.  This does eliminate the Javascript error (after a little debugging of my own).  However I am not getting any results that contain the " in them.  Instead I get an empty grid.

Thanks
0
Veli
Telerik team
answered on 29 Jun 2011, 09:38 AM
Hi Brett,

I am attaching the test page I used for this scenario. Let me know how this works for you and what is different in your case.

Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Brett
Top achievements
Rank 1
answered on 30 Jun 2011, 12:23 AM

I have found what was different.  The page in the example has a plain text " while I have encoded all of my data to be HTML safe.  I am using HttpUtility.HttpEncode on my data source, thus a " is actually &quot; which is why no results were returning.  Its the little things in life that get you. Below is the modified version that now properly returns results for me.

Thank you for the help and response.

protected void HandleQuotes(RadFilterGroupExpression expression)
        {
            var expressions = expression.Expressions;
 
            foreach (var expr in expressions)
            {
                if (expr is RadFilterSingleValueExpression<string>)
                {
                    var stringExpr = (RadFilterSingleValueExpression<string>)expr;
                    stringExpr.Value = stringExpr.Value.Replace("\"", HttpUtility.HtmlEncode("\""));
                }
 
                if (expr is RadFilterGroupExpression)
                {
                    HandleQuotes((RadFilterGroupExpression)expr);
                }
            }
        }
0
Raji
Top achievements
Rank 1
answered on 29 Jul 2011, 05:45 PM
Hi Veli,

The code is really helpful. I am using .Net 2.0 so I can not use 'var' keyword specified in your code. Is their an alternative code that I can use to loop through the expressions using .Net 2.0. Early help will be appreciated.

Thanks,
Raji
Tags
Filter
Asked by
Brett
Top achievements
Rank 1
Answers by
Veli
Telerik team
Brett
Top achievements
Rank 1
Raji
Top achievements
Rank 1
Share this question
or